[英]How to iterate through a list of an anonymous type
我有一个国家列表,我想分别获取国家名称和CountryID。
为了更容易理解,请访问我上传图像的链接
alt text http://img251.imageshack.us/img251/8505/listx.jpg
http://img251.imageshack.us/img251/8505/listx.jpg
匿名类型怎么可能?
我试过了国家[0] [“国家”],但没有运气。
只需循环遍历您的列表 - 匿名类型是匿名的 - 但仍然是严格的类型! 您可以获得intellisense,并且应该能够完全访问字段Country
和CountryID
:
foreach(var c in yourListOfCountries)
{
string countryName = c.Country;
int countryID = c.CountryID;
}
渣
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.