ienumerable

Split a collection into n parts with LINQ, in VB.Net

ぃ、小莉子 提交于 2019-12-14 00:55:42
问题 Question In VB.Net, If I have a collection like this: Dim collection As IEnumerable(Of Integer) = Enumerable.Range(0, 99) How I could split it in groups/Ienumerables of an indeterminated amount of elements? Conditions Using a LINQ query (not MORELinq or any other 3rd party libs) Not writting a Function , just using (or appending to the collection) a LINQ query avoiding the insertion of a custom and generic procedure to split in parts. Not generating an Anonymous Type (because I will respect

How to populate one extra property in a .Select - LINQ [duplicate]

不想你离开。 提交于 2019-12-13 20:21:42
问题 This question already exists : How to solve Npgsql.NpgsqlOperationInProgressException: A command is already in progress Closed 2 months ago . I'm using my Map method to create DTO object from my context class Company and it looks like this: private CompDTO Map(Company company) { return new CompDTO() { Id = company.Id, Title = company.Title, ParentCompanyId = company.ParentCompanyId, }; } CompDTO looks like this: public class CompDTO { public long Id { get; set; } public string Title { get;

Group and concatenate List of tuples

ぃ、小莉子 提交于 2019-12-13 20:05:40
问题 I have a list of pairs (key, val) with both key and value being strings. I want to aggregate the tuples with duplicate keys. For (key1, val1), (key2, val2), (key3, val3), (key1, val4), (key2, val5) I want output (key1, val1+val4), (key2, val2+val5) This is my current query var duplicates = Contents.Records.SelectMany(x => x.Users).Select(x => new { Name = x.Name, ID= x.ID}).GroupBy(x => x.ID).Select(x => new { x.Key, Names = x.Select(p=>p.Name).Aggregate((a,b) => a +","+b)}).ToArray(); But at

Exception not showing list values

大憨熊 提交于 2019-12-13 19:41:25
问题 In my Exception class, I pass an IEnumerable of IpAddresses. When the exception is thrown, this is what I see. How come it doesn't give me an option to see the values inside my IEnumerable? Here's the code that's causing the problem: public class CustomException : Exception { public List<string> IpAddresses { get; private set; } public CustomException(string message, IEnumerable<string> ipAddresses) : base(message) { IpAddresses = ipAddresses; } } Thanks in advance. 回答1: I figured out the

Order IEnumerable by occurrences

纵饮孤独 提交于 2019-12-13 19:14:50
问题 I have an enumerable collection of entities which have come from Linq2Sql (they have been enumerated to an array by this stage). The collection may (probably will) contain multiple occurrences of the same entity. How would I go about ordering the collection so that entities which occurred most often are moved to the front? IEnumerable<Entity> results = SearchForEntities(searchCriteria); return results.OrderByDescending(e => /* Number of occurences in results? */) .Distinct() .Take

Even “IsNullOrEmpty” checks give “Possible multiple enumeration of IEnumerable” warnings

本秂侑毒 提交于 2019-12-13 12:52:41
问题 There's a question on SO about "possible multiple enumerations" already, but this question is more specific. Please consider the following method, which takes an IEnumerable<string> as input and executes a given method against each of its elements: public static bool SomeMethod(IEnumerable<string> enumerable) { if (enumerable.IsNullOrEmpty()) { // throw exception. } else { return (enumerable.All(SomeBooleanMethod)); } } In the code above, IsNullOrEmpty is just an extension method which runs

最全数据结构详述: List VS IEnumerable VS IQueryable VS ICo

老子叫甜甜 提交于 2019-12-13 11:54:41
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 本文对常用的数据结构详述:Array, ArrayList,List,IList,ICollection, Stack, Queue, HashTable, Dictionary, IQueryable, IEnumerable。 Collection(集合) Collection是数据记录集合, 编写代码过程中,常常需要合适的容器保存临时数据,方便修改和查找,如何选取合适的数据容器,关键在于将执行的数据操作以及数据记录是否大量。 Array(数组) 特征 1. 固定大小,数组的大小是初始化时决定无法修改的数值。 2. 强类型,存储数据元素类型必须在初始化时指定,因此在运行时,不需要耗费额外的时间来定义数组类型,能够大大提升运行效率。 3. 可使用Foreach关键字实现数组迭代和查找。 因为数组大小是固定的,且是强类型数据结构,因此在运行时只占用很少的内存,运行时效率很高。 1: //It is obvious that strArray is 2: //1. string --> Strongly Type 3: //2. Sized=10 --> Fixed Size 4: 5: string [] strArray = new string [10]; 6: 7: for ( int i = 0; i

IList,ICollection,IEnumerable,IEnumerator,IQueryable

天大地大妈咪最大 提交于 2019-12-13 11:41:48
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> IList 是 ICollection 接口的子代,并且是所有非泛型列表的基接口。IList 实现有三种类别:只读、固定大小和可变大小。无法修改只读 IList。固定大小的 IList 不允许添加或移除元素,但允许修改现有元素。可变大小的 IList 允许添加、移除和修改元素。 ICollection 接口是 System.Collections 命名空间中类的基接口。ICollection 接口扩展 IEnumerable;IDictionary 和 IList 则是扩展 ICollection 的更为专用的接口。 IDictionary 实现是键/值对的集合,如 Hashtable 类。 IList 实现是值的集合,其成员可通过索引访问,如 ArrayList 类。 某些集合(如 Queue 类和 Stack 类)限制对其元素的访问,它们直接实现 ICollection 接口。 如果 IDictionary 接口和 IList 接口都不能满足所需集合的要求,则从 ICollection 接口派生新集合类以提高灵活性。定义所有非泛型集合的大小、枚举器和同步方法。 IQueryable 提供对未指定数据类型的特定数据源的查询进行计算的功能,IQueryable 接口由查询提供程序实现。 该接口只能由同时实现

Design issues and implementing Enumerable.AsEnumerable<FarPoint.Win.Spread.Row>

微笑、不失礼 提交于 2019-12-13 09:35:43
问题 How can i make a datatype return IEnumerable<datatype> if it does not have AsEnumerable() method. For example: FarPointSpread1.ActiveSheet.Rows[e.Row] does not contain AsEnumerable() so i cannot do this FarPointSpread1.ActiveSheet.Rows[e.Row].AsEnumerable() e.Row is the current row in the spread's activesheet and i am expecting to be able to do something like this: IEnumerable<FarPoint.Win.Spread.Row> = FarPointSpread1.ActiveSheet.Rows[e.Row].AsEnumerable(); I want to iterate over all fields

GetEnumerator Error with Custom Type

穿精又带淫゛_ 提交于 2019-12-13 08:59:47
问题 I have the following Class... class gridRecord { //Constructor public gridRecord() { Quantity = new quantityField(); Title = new titleField(); Pages = new pagesField(); } private quantityField quantity; private titleField title; private pagesField pages; internal quantityField Quantity { get { return quantity; } set { quantity = value; } } internal titleField Title { get { return title; } set { title = value; } } internal pagesField Pages { get { return pages; } set { pages = value; } } } I