Questions tagged [ienumerable]

IEnumerable, and its generic counterpart IEnumerable are .NET interfaces for iterating (or enumerating) through a collection of items.

The IEnumerable interface (in the System.Collections namespace) contains only a single member, the GetEnumerator() method, which returns an IEnumerator.

The generic counterpart to IEnumerable, IEnumerable<T> (added to the System.Collections.Generic namespace in the .NET framework 2.0) also contains only a single member, the GetEnumerator() method; this returns an IEnumerator<T>.

Interaction with the IEnumerable<T> interface is often done through extension methods, for example First(), Last() and Count().

It is possible to obtain a generic IEnumerable<T> from an IEnumerable by calling either of the extension methods Cast<T>(), or OfType<T>(), depending on the case.

3522 questions
2
votes
0 answers

Exception with Custom expression builder with ICollection / IEnumerable

I have been trying to write a method that will build an expression based on types and parameters passed in. Currently the method is: // tuple: CollectionName, ClassName, PropertyName public Expression> BuildCollectionWithLike
user3161050
  • 111
  • 1
  • 14
2
votes
1 answer

Cast IEnumerable to Episerver PageDataCollection

How could i get a Linq Query back to Episerver PageDataCollection? I cant find anything about it on the net. //This becomes IEnumerable i need it to be PageDataCollection var banners = DataFactory.Instance …
Daarwin
  • 2,896
  • 7
  • 39
  • 69
2
votes
1 answer

Difference between create Enumerable or Enumerator using Iterators in C#

What is the difference between creating Enumerable or Enumerator using Iterators in C#? I know that Iterators are used to create a private class that implements Enumerable or Enumerator... Which way is better to create an enumerable type?
Csharper
  • 27
  • 5
2
votes
1 answer

deserializing child data collections into ienumerables using JSON.NET

Current I have a project where I'm getting the following sample data ( I want to retrieve only the ids within this json string and stuff them into IEnumerables (explained below): { "states": [ { "id": "AL", "text": "Alabama (AL)" …
sksallaj
  • 3,872
  • 3
  • 37
  • 58
2
votes
5 answers

Why is Enumerable.Count() throwing `InvalidOperationException` for converting `null` to `bool`?

Can anyone explain how on earth the following statement can generate System.InvalidOperationException: The value null not be assigned a member of type System.Boolean since it is a value type that cannot have the value null (freely translated from…
Martin
  • 2,956
  • 7
  • 30
  • 59
2
votes
1 answer

Binding LinqToSql tables to Repeater

I have a class which retrieves the data from DB. [Table(Name = "Ilanlar")] public class Ilan { [Column(Name="ilan_id" ,IsPrimaryKey = true)] public int M_ilan_id; [Column(Name="refVerenUser_id")] public int…
uzay95
  • 16,052
  • 31
  • 116
  • 182
2
votes
4 answers

Casting to custom type, Enumerable.Cast and the as keyword

This is more a question out of curiosity than necessity and came about having had to deal with Active Directory (MS) types such as SearchResultCollection (in the System.DirectoryServices namespace). Frequently when dealing with AD in code, I find…
peteski
  • 1,455
  • 3
  • 18
  • 40
2
votes
2 answers

C# How to use .OrderBy with multiple columns and decode column number to column name?

So I'm using Datatable.net, Asp.net MVC Controller serving up Json data. I'm trying to do something simliar to these posts: LINQ Sort by Multiple Fields Multi Column Sort for Datatables.net I have the following parameters from the Javascript Ajax…
Ben_Coding
  • 398
  • 6
  • 17
2
votes
2 answers

Why I need to enumerate my list inside the program's logic for it to work in this case?

I have this simple piece of code: IEnumerable reports = _model.GetAllAccessEvents(); foreach (var ap in AccessPoints.Where(x => !x.IsChecked)) reports = reports.Where(x => x.AccessPointId != ap.Id); It should remove the non checked…
André Santaló
  • 639
  • 1
  • 9
  • 24
2
votes
1 answer

Behavior of ObservableCollection(IEnumerable) constructor

According to MSDN there is an overload for the ObservableCollection constructor to which you can pass an IEnumerable. According to the very short MSDN page this will make a "Copy" of the Ienumerable. How do I determine how this will behave? Will the…
Mike B
  • 2,592
  • 3
  • 33
  • 46
2
votes
2 answers

Can you stack multiple IEnumerable queries?

Do Linq methods on IEnumerable objects stack or do they override previous methods? For example string[] exampleArray = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; IEnumerable iEnum1 = exampleArray.Skip(1); IEnumerable iEnum2 =…
Puddler
  • 2,619
  • 2
  • 17
  • 26
2
votes
4 answers

How to order IEnumerable based on a predefined sequence?

I have a IEnumerable. public class Process { public string Id { get; set; } public string Name { get; set; } public int Type { get; set; } } I want to order this IEnumerable based on Type. The ordering should be based…
Sartorial
  • 173
  • 1
  • 8
2
votes
2 answers

Select unique/distinct combination of values from IEnumerable of same type

I have three IEnumerables of the same type (string) and I want to get unique combinations of values from it. Not quite sure how to implement LINQ in here. The result should be a list of something like this by adding - as…
Indigo
  • 2,887
  • 11
  • 52
  • 83
2
votes
4 answers

How do interfaces like IEnumerable work without proper implementation?

From what I understand on interfaces, is that in order to use them, you must declare that a class is implementing it by adding the name of the interface after a colon and then, implement the methods. I'm currently learning about Enumerators,…
ab1428x
  • 794
  • 2
  • 8
  • 20
2
votes
2 answers

LINQ Contains vs Intersect (vs anything else!)

I have a large IEnumerable of EntityObjects and a large IEnumerable of strings, which are a key of the objects. I want to obtain a new list of only the objects where the key is matched. At the moment I am doing this through Contains() - but it…
BlueChippy
  • 5,935
  • 16
  • 81
  • 131