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

Fastest way to set properties to null in C# 4

What is the fastest way to set properties (any one) to null in an IEnumerable? Is foreach my only option?
Greens
  • 3,061
  • 11
  • 43
  • 61
2
votes
6 answers

Why can't I foreach through my ViewData or Model?

I keep getting errors trying to iterate through my ViewData in the view there... I even tried strongly typing the view to IEnumerable(App.Models.Namespace) and using Model, to no avail. Either I get an error for lack of a GetEnumerable method or…
MetaGuru
  • 42,847
  • 67
  • 188
  • 294
2
votes
2 answers

Linq and IEnumerable lazy query. Efficiency lost?

I've been reading that Ienumerables don't run straight away. So I'm trying to find the best way to query a list. Below is my getAll method. Followed by my filter method. Followed by a preferred filter method (Readability). My question is, will the…
Mcloving
  • 1,390
  • 1
  • 13
  • 30
2
votes
1 answer

IEnumerable Collection Gets Cleared upon WCF Transfer

I have a class(say CustomClass) which has few properties of type IEnumerable. Pass the object of CustomClass over the WCF and return object of Result type(different type). If I check CustomClass parameter in WCF after its gets everything done…
Manvinder
  • 4,495
  • 16
  • 53
  • 100
2
votes
1 answer

Why can't I use BindingList as a parameter to a method that takes BindingList?

Basically I have a method with the following signature: public void Save(BindingList items); and I'm trying to call it using classInstance.Save(items); //items = BindingList but it seems that C# doesn't realize the…
PedroC88
  • 3,708
  • 7
  • 43
  • 77
2
votes
3 answers

C# accessing IEnumerable collections

I am fairly new to working with collections so please bear with me my jargon might not even be accurate. I have PetaPoco returning query results as an IEnumerable, one collection for each result. I want to evaluate the collections to get a specific…
Mark Hollas
  • 1,107
  • 1
  • 16
  • 44
2
votes
3 answers

Creating a select list from an array

Possible Duplicate: how to find the index particular items in the list using linq? I am trying to create a IEnumerable from an array of strings. string[] months = { "January", "February", "March", "April", "May", "June", "July",…
Jeff
  • 2,283
  • 9
  • 32
  • 50
2
votes
4 answers

Returning IEnumerable from Linq query

I'm trying to return an IEnumerable from a linq query and I'm getting the error: Cannot convert IEnumerable to IEnumerable I have no idea how to go about fixing this issue. private IEnumerable
litterbugkid
  • 3,534
  • 7
  • 36
  • 54
2
votes
1 answer

Concat multiple IEnumerables with constraint

I have an object with multiple Offers assigned through different ways. An Offer is exactly for one Product and an object has multiple Offers. Now I want all Offers of an object following a specifig business logic that a Product is contained only…
niklr
  • 1,671
  • 3
  • 24
  • 40
2
votes
3 answers

count non-null elements of IEnumerable

I have a view model in asp .net mvc 3 which has IEnumerable files In the view, I have a for loop that creates 9 input tags for these files. I want to implement a check on the server-side to ensure atleast 3 files are being…
Tripping
  • 919
  • 4
  • 18
  • 36
2
votes
2 answers

Mapping Linq Group By Results To An Object

I have a class that acts as a summary which is going to be passed to an MVC View as an IEnumerable. The class looks like: public class FixedLineSummary { public long? CustomerId { get; set; } public string CustomerName { get; set; } …
GrahamJRoy
  • 1,603
  • 5
  • 26
  • 56
2
votes
2 answers

How do I properly convert from a LINQ Result (as IEnumerable) to a delimited list without using reflection in .net?

First of all, please forgive if I am way off on this as I am somewhat new to .net, anonymous types, and LINQ. Frankly I'm struggling a bit and plan to do a lot of learning over the next month on the topic. I know enough to know what I have come up…
user1646212
  • 21
  • 1
  • 3
2
votes
1 answer

Choosing return type of collection: Is there a way to return the same type that is provided?

I'm in a dilemma to choose the return type of collections when writing generic extension methods for an API. I have read discussions on SO on what collection type to return and what should be the design choices. I generally prefer to accept the most…
nawfal
  • 70,104
  • 56
  • 326
  • 368
2
votes
1 answer

Why is the `IDictionary.Values` property of type `ICollection`?

I'm trying to wrap my head around why the IDictioary.Values property is of type ICollection as opposed to IEnumerable. The .NET implementation of the Values property implements the interface property explicitly and then…
Anthony
  • 9,451
  • 9
  • 45
  • 72
2
votes
2 answers

C# how to convert IEnumerable anonymous lists into data table

Many solutions are available that convert lists to DataTable that use reflection, and that would work for converting anonymous types. However, it there are lots of lists of anonymous types, then performance can be an issue. Is this the only way to…
nag
  • 920
  • 6
  • 27
  • 51
1 2 3
99
100