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
3 answers

Can't find the error in this usage of a collection's enumerator

I want to define a collection with an enumerator that can be set at run time. I defined an enumerator: public class JuniorEmployeeEnumerator : IEnumerable { List list = new List(); public…
Rafael
  • 2,413
  • 4
  • 32
  • 54
2
votes
5 answers

How can I add an element to an IEnumerable in C#

I have the following code: var contentTypes = ( from contentType in this._contentTypeService.GetContentTypes() select new { id = contentType.ContentTypeId, …
Alan2
  • 23,493
  • 79
  • 256
  • 450
2
votes
6 answers

IEnumerable question: Best performance?

Quick question: Which one is faster? foreach (Object obj in Collection) { if(obj.Mandatory){ ... } } or foreach (Object obj in Collection.FindAll(o => o.Mandatory)) { ... } and if you know a faster suggestion, i'd be pleased to know. Thank…
Eduardo Mello
  • 925
  • 3
  • 15
  • 32
2
votes
2 answers

IEnumerable to Dictionary>

I suppose that this question might partially duplicate other similar questions, but i'm having troubles with such a situation: I want to extract from some string sentences For example from `string sentence = "We can store these chars in separate…
mihai
  • 2,746
  • 3
  • 35
  • 56
2
votes
3 answers

Equality between two IEnumerable> objects

I don't think SequenceEqual is working between the two because the "middle" elements (IEnumerable) aren't using SequenceEqual. oneThingy.SequenceEqual(twoThingy) Short of using String.Join on the middle elements, is there a way to get…
Wilson
  • 8,570
  • 20
  • 66
  • 101
2
votes
1 answer

parse.com c# query, how to get the results?

I'm trying to read some data from the parse.com database in the cloud in a c# .net application but i'm stuck at getting at the values I'm after. The code as it stands is called on app launch (for now): Console.WriteLine("called app launch"); …
user2313394
  • 21
  • 1
  • 3
2
votes
1 answer

Loop through list of objects inside object

I'm using mvc and I'm passing the class called DataModel as my model to the view: public class DataModel { public List statsPerMonthPerServer { get; set; } } And here is the class ServerStats: public class ServerStats { …
Ashkan Hovold
  • 898
  • 2
  • 13
  • 28
2
votes
0 answers

Simple sort verification for unit testing an ORDER BY?

I'm working on a DAL method that uses an ORDER BY clause in a SELECT. The return value from the method is an IEnumerable, where T is a class that encapsulates a domain entity, and the sort order would be based on one of the properties of this…
AJ.
  • 16,368
  • 20
  • 95
  • 150
2
votes
3 answers

Ideal C# IEnumerable generic number sequence with start and interval

I was looking for, but could not find, an idiomatic example for a generic class implementing IEnumerable, which does this: constructor takes start and interval, and GetEnumerator returns IEnumerator, which starts from starts and goes on forever…
hyde
  • 60,639
  • 21
  • 115
  • 176
2
votes
1 answer

IEnumerable has values but still gives System.NullReferenceException

I am populating an IEnumerable using a LINQ query. The IEnumerable is then passed into another class and appended as a parameter (to a Telerik report). On this line, I'm getting a System.NullReferenceException. Through debugging I've confirmed…
user1287523
  • 967
  • 3
  • 14
  • 31
2
votes
2 answers

IEnumerator / IEnumerable with position stored only temporarily?

I'm developing a graph where I need to keep the memory usage per node as low as possible. Each node implements IEnumerator / IEnumerable. IEnumerator / IEnumerable make use of "position" in the canonical examples, which is a persistent cursor value…
Engineer
  • 8,529
  • 7
  • 65
  • 105
2
votes
10 answers

Using List Distinct() to return 2 values

I have a Person class, with Name and AreaID properties. public class Person { public string Name; public int AreaID; // snip } I have a List with the potential for hundreds of Person objects in the list. e.g., 100 Persons with…
Jon
  • 38,814
  • 81
  • 233
  • 382
2
votes
1 answer

How to convert IDictionary > to IDictionary >?

I have a function that return a IDictionary >. I have another function that takes a IDictionary >. I need to pass the return of the first function to the second function. The compiler doesn't want to…
Cyril Gandon
  • 16,830
  • 14
  • 78
  • 122
2
votes
2 answers

How do I set a local variable during a LINQ query expression?

How can I increment counter while inside a LINQ query? Consider the following Public Class SimpleString Public Property Value As String End Class ... Public Shared Sub SetStuff() Dim stringList As IEnumerable(Of SimpleString) = …
Rowan Freeman
  • 15,724
  • 11
  • 69
  • 100
2
votes
1 answer

Find the index of a specific combination without generating all ncr combinations

I am trying to find the index of a specific combination without generating the actual list of all possible combinations. For ex: 2 number combinations from 1 to 5 produces, 1,2;1,3,1,4,1,5;2,3,2,4,2,5..so..on. Each combination has its own index…
FairDinkum82
  • 167
  • 2
  • 11