我的一个api将返回ICollection结果,我想在我的代码中读取它们而不使用System.Linq.有可能吗?
添加更多---当我使用Linq,ICollection.First().值很好..我想要的方式应该像使用Linq一样工作.
谢谢帕万
是的,你可以简单地使用foreach循环.
编辑:要访问特定元素,您可以像在其他答案中一样使用索引访问.如果您需要特定条件,则可以迭代集合
ICollection<TYPE> collection = YourApi();
TYPE result;
foreach(var x in collection)
{
if( your condition is true )
{
result = x;
break;
}
}
// check if result is not null and use it
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3592 次 |
| 最近记录: |