【发布时间】:2010-10-07 05:24:16
【问题描述】:
以下 lambda 语句返回 null,而我希望它会返回一个字符串值。
var countryCode = AddressComponents
.Where(x => x.AddressType == AddressType.Country)
.Select(x => x.ShortName)
.SingleOrDefault();
现在我正在查询的当前实例的 AddressType 属性包含以下数据:
AddressType.Political | AddressType.Country
所以它包含两个值。
当然,我的 lambda 不起作用,因为 country 的值(假设它是 1)!= 政治位或 Country 的值(假设它是 1 | 2 == 3)。
有什么想法吗?
我担心我需要一些非常丑陋的东西,比如......
((AddressTypes & AddressType.Country) == AddressType.Country)
.. 想法?
【问题讨论】:
标签: .net linq enums lambda bit-manipulation