Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个名为地址的列表。现在我想要 Address.City 名称,其中 Address.Zip = 822。如何通过在列表中选择查询从地址列表中访问城市名称?
这是非常简单的 LINQ。
string city = Address .Where(a => a.Zip == 822) .Select(a => a.City) .FirstOrDefault();
尝试,
Address obj = list.FirstOrDefault(o => o.Zip == 822); if (obj != null) { string city = obj.City; }