草庐IT

IEnumerable

全部标签

c# - 任何人都可以向我解释 IEnumerable 和 IEnumerator 吗?

关闭。这个问题需要更多focused.它目前不接受答案。想改进这个问题吗?更新问题,使其只关注一个问题editingthispost.关闭3年前。Improvethisquestion谁能给我解释一下IEnumerable和IEnumerator?例如,什么时候在foreach上使用它?IEnumerable和IEnumerator有什么区别?为什么我们需要使用它?

c# - 从 IList<string> 或 IEnumerable<string> 创建逗号分隔列表

从IList创建逗号分隔的字符串值列表的最简洁方法是什么?或IEnumerable?String.Join(...)在string[]上运行所以使用诸如IList之类的类型会很麻烦或IEnumerable不能轻易转换为字符串数组。 最佳答案 .NET4+IListstrings=newList{"1","2","testing"};stringjoined=string.Join(",",strings);详细信息和Pre.Net4.0解决方案IEnumerable可以使用LINQ(.NET3.5)非常轻松地转换为字符串数组:IEn

c# - 从 IList<string> 或 IEnumerable<string> 创建逗号分隔列表

从IList创建逗号分隔的字符串值列表的最简洁方法是什么?或IEnumerable?String.Join(...)在string[]上运行所以使用诸如IList之类的类型会很麻烦或IEnumerable不能轻易转换为字符串数组。 最佳答案 .NET4+IListstrings=newList{"1","2","testing"};stringjoined=string.Join(",",strings);详细信息和Pre.Net4.0解决方案IEnumerable可以使用LINQ(.NET3.5)非常轻松地转换为字符串数组:IEn

c# - Select 和 SelectMany 的区别

我一直在寻找Select和SelectMany之间的区别,但一直找不到合适的答案。我需要了解使用LINQToSQL时的区别,但我发现的只是标准数组示例。有人可以提供LINQToSQL示例吗? 最佳答案 SelectMany扁平化返回列表列表的查询。例如publicclassPhoneNumber{publicstringNumber{get;set;}}publicclassPerson{publicIEnumerablePhoneNumbers{get;set;}publicstringName{get;set;}}IEnumer

c# - Select 和 SelectMany 的区别

我一直在寻找Select和SelectMany之间的区别,但一直找不到合适的答案。我需要了解使用LINQToSQL时的区别,但我发现的只是标准数组示例。有人可以提供LINQToSQL示例吗? 最佳答案 SelectMany扁平化返回列表列表的查询。例如publicclassPhoneNumber{publicstringNumber{get;set;}}publicclassPerson{publicIEnumerablePhoneNumbers{get;set;}publicstringName{get;set;}}IEnumer

c# - 返回 IEnumerable<T> 与 IQueryable<T>

返回IQueryable有什么区别?与IEnumerable,什么时候应该优先选择一个?IQueryablecusts=fromcindb.Customerswherec.City==""selectc;IEnumerablecusts=fromcindb.Customerswherec.City==""selectc;两者都会被延迟执行吗?什么时候应该优先执行一个? 最佳答案 是的,两者都会给你deferredexecution.区别在于IQueryable是允许LINQ-to-SQL(实际上是LINQ.-to-anything)

c# - 返回 IEnumerable<T> 与 IQueryable<T>

返回IQueryable有什么区别?与IEnumerable,什么时候应该优先选择一个?IQueryablecusts=fromcindb.Customerswherec.City==""selectc;IEnumerablecusts=fromcindb.Customerswherec.City==""selectc;两者都会被延迟执行吗?什么时候应该优先执行一个? 最佳答案 是的,两者都会给你deferredexecution.区别在于IQueryable是允许LINQ-to-SQL(实际上是LINQ.-to-anything)

等效于 LINQ Any() 的 JavaScript/jQuery

有没有等价于IEnumerable.Any(Predicate)的在JavaScript或jQuery中?我正在验证项目列表,如果检测到错误,我想尽早中断。我可以使用$.each来做到这一点,但我需要使用外部标志来查看是否确实找到了该项目:varfound=false;$.each(array,function(i){if(notValid(array[i])){found=true;}return!found;});什么是更好的方法?我不喜欢使用普通的for使用JavaScript数组,因为它遍历其所有成员,而不仅仅是值。 最佳答案

等效于 LINQ Any() 的 JavaScript/jQuery

有没有等价于IEnumerable.Any(Predicate)的在JavaScript或jQuery中?我正在验证项目列表,如果检测到错误,我想尽早中断。我可以使用$.each来做到这一点,但我需要使用外部标志来查看是否确实找到了该项目:varfound=false;$.each(array,function(i){if(notValid(array[i])){found=true;}return!found;});什么是更好的方法?我不喜欢使用普通的for使用JavaScript数组,因为它遍历其所有成员,而不仅仅是值。 最佳答案

c# - 创建常量 IEnumerable<TSomeType>...的方法?

也许这是一个愚蠢的问题...但是创建常量IEnumerable的最佳(性能和内存方面)方法是什么?...?如果无法定义“最佳”方式,我有哪些选择?您的意见是什么,您认为有最合适的方法吗?例如:varenumerable=(IEnumerable)newList{Value1,Value2,Value3};varenumerable=(IEnumerable)newTSomeType[]{Value1,Value2,Value3};(其他一些选项;例如LinqSelect)。请考虑到内存和性能是这里的一个问题-我们谈论的是一个真正受限的环境(安装了.NET的小型设备)。提前致谢。