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

IEnumerable interface and Skip method in Mono

I'm looking for the Skip method of IEnumerable interface. IList public IEnumerable interface, so I thought I was able to access that method. Anyway the following code fails to compile on Mono: private static void SkipFirst(IList list) { …
Heisenbug
  • 38,762
  • 28
  • 132
  • 190
2
votes
1 answer

Are there any tools that can help us refactor IEnumerator properties to IList or similar?

We have a very old code base(that actually is not horrible quality). It dates back to when .Net was pre-release, which I suspect is the cause of some of these weird conventions. Anyway, we just began to drop .Net 1.1 support and are having a…
Earlz
  • 62,085
  • 98
  • 303
  • 499
2
votes
2 answers

getting selected value of IEnumerable from Drop Down List

I have a dropdown list as below: DropDownList1.DataSource = Students.GetStudents(); DropDownList1.DataBind(); ----------- I have a DataAccess Class as below: public IEnumerable GetStudents() { List studentsList = new…
saklo
  • 111
  • 1
  • 11
2
votes
3 answers

Selecting IEnumerable from JOIN results in a complex Linq-to-SQL query

I've got a query that looks like this: var orderLines = from Order order in _orders join OrderItem orderItem in dbc.OrderItems on order.OrderId equals orderItem.OrderId join Product product in…
Polynomial
  • 27,674
  • 12
  • 80
  • 107
2
votes
1 answer

Any convention for an IEnumerable to report immutability and other characteristics?

In many cases, code will receive an IEnumerable and wish to persist the sequence of items contained therein. A common way to do this is to call ToList on it. If the implementation in question is already an immutable list, however, calling…
supercat
  • 77,689
  • 9
  • 166
  • 211
2
votes
2 answers

Mvc3 IEnumerable have a List property. When I post, I get null list

I'm making a survey application. Survey has Questions and Questions have QuestionOption. haveThere is a example here. I am trying to use this technique in a large form with a list(List) but when I post back, the Viewmodel.Order that should’ve…
sbb
  • 529
  • 3
  • 25
2
votes
2 answers

c# recursion - "Collection was modified; enumeration operation may not execute"

I am trying to use recursion to go up a hierarchy, and i get this error: Collection was modified; enumeration operation may not execute. My assumption here is that when it enters the function each time, it is using the same parentRolesCopy and not…
Kyle
  • 32,731
  • 39
  • 134
  • 184
2
votes
3 answers

Order a List by inner field of object

Consider the code below class Pin { string Name; //can be either Numerical or AlphaNum } enum Place { Left, Right } class Map { Pin pin; Place Place; Rectangle Rect; } The Pin's Name field can be only numerical or…
Dumbo
  • 13,555
  • 54
  • 184
  • 288
2
votes
4 answers

When does IEnumerable.Any(Func) return a value?

I recently saw a bit of code in a codebase I work with, where ReSharper offered to refactor it to collection.Any(Func< bool >). I'm wondering about the performance impacts of this. Say I have a call that looks like this: bool hasEvenValue =…
Andrew Gray
  • 3,756
  • 3
  • 39
  • 75
2
votes
3 answers

Updating string properties of an object using enumeration

I have a load of text boxes on an aspx page whose IDs are prefixed with 'txt' the rest of the ID has a corresponding property of the same name in a certain object. I want to be able to enumerate through these string properties and update them where…
Roooss
  • 626
  • 1
  • 9
  • 24
2
votes
3 answers

C# implementing generic IEnumerable

I have been wondering if it is possible to make say State class implementing IEnumerable and IEnumerable so I could get all the people living in the state via foreach as well as all the cities. It won't even compile saying this: Error…
Nikolas Jíša
  • 699
  • 1
  • 11
  • 29
2
votes
1 answer

Custom Generic IEnumerator Tied To A Database

The work I do involves downloading into memory HUGE amounts of data from a SQL server database. To accomplish this, we have custom dataset definitions that we load using a SqlDataReader, then iterate through the Datatable and build each row into an…
Jared275
  • 49
  • 2
  • 11
2
votes
1 answer

Nunit difference between `Assert.AreEqual` and `CollectionAssert.AreEqual` for IEnumerables

In Nunit, is there any difference between Assert.AreEqual(IEnumerable, IEnumerable) and CollectionAssert.AreEqual(IEnumerable, IEnumerable) ?
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
2
votes
2 answers

What is the meaning of this code? (IEnumerable query = from num in list)

What's the meaning of this: IEnumerable query = from num in list where num < 3 select num; Is this an object as IEnumerable? Can anyone please describe this?
ramin_rp
  • 321
  • 1
  • 4
  • 14
2
votes
3 answers

ASP.Net MVC 3, Using ViewModel, error that ViewModel is not IEnumerable

OK, after searching and searching here, Google and other programming sites, it's time for me to ask my first question. I have a view, Index.cshtml, that I need two Models in, so I created a ViewModel, ImageViewModel.cs, the two children models,…
SouthPlatte
  • 297
  • 2
  • 7
  • 17
1 2 3
99
100