Click here to Skip to main content
15,894,330 members
Everything / Ienumerable

Ienumerable

IEnumerable

Great Reads

by Muraad Nofal
A haskell monad/(applicative)functor like interface in C# that extends IEnumerable.
by Kabwla.Phone
Ha! I get it....I am actually using an adaptation of this technique in production code.But the adapted code required a dept-first search and this original pattern is width-first.Which brings us these new and improved versions:public static List FindControlsWidthFirst( Control...
by Namlak
string blah = string.Join(",", cities.Select(c=> c.Name));
by ASP.NET Community
The iterator pattern’s role is to provide a way to access aggregate objects sequentially without the knowledge of the structure of the aggregate.

Latest Articles

by Mike-MadBadger
This is an alternative for "Pick Your Enumerator & Me.Understand Yield and IEnumerable (C#)"
by Ramesh Bevara
An overview of a helper class to build dynamic order by clause in LINQ query in C#
by WyoMetz
Simple and easy paging of a WPF DataGrid with DataTable and LINQ queries
by Jörgen Andersson
A propertymapping extension for DataReaders

All Articles

Sort by Score

Ienumerable 

18 Sep 2013 by Muraad Nofal
A haskell monad/(applicative)functor like interface in C# that extends IEnumerable.
25 Nov 2011 by Kabwla.Phone
Ha! I get it....I am actually using an adaptation of this technique in production code.But the adapted code required a dept-first search and this original pattern is width-first.Which brings us these new and improved versions:public static List FindControlsWidthFirst( Control...
18 Jan 2012 by Namlak
string blah = string.Join(",", cities.Select(c=> c.Name));
19 Oct 2013 by ASP.NET Community
The iterator pattern’s role is to provide a way to access aggregate objects sequentially without the knowledge of the structure of the aggregate.
22 Apr 2019 by F-ES Sitecore
Your data has a property called "result" which is an array so you need a class that reflects that. Something like class MyData { [JsonProperty("result")] public List Result { get; set; } [JsonProperty("success")] public bool Success { get; set; }...
29 Jul 2020 by Chris Copeland
If your Get(int id) method is the one producing the JSON response, you can probably change the return type from IEnumerable to Points and then simply return the first result in the dt.Rows collection? The reason that it's being formatted...
29 Aug 2013 by Maarten Kools
The IEnumerable interface is basically a type-safe IEnumerable. The T in this case is a so called generic type parameter. It defines that the IEnumerable will contain objects of type T.There's a lot of resources to find on using generics on the internet, here's some to get...
18 Jan 2014 by Karthik_Mahalingam
You can simulate with this Questions List - main listQuestionsOptions list - secondary list Respose List - secondary listfor example: join 1 ( question list and question option list ) -> it will give 2 rowsjoin 1 results joined with Resonse list -> gives 4 rows as the parent(for...
17 Mar 2014 by CPallini
You may use a dictionary to map the Type Ids to your own order criterion, e.g.Dictionary mo = new Dictionary{ { 3, 0 }, { 5, 1 }, {2,2}, {4,3}, {6,4} };Thendocuments.OrderBy(d => mo[d.Type.Id])
3 Oct 2014 by Richard Deeming
So you want to take the top 5 news items for the current language, and then filter out any where subscriber 5 isn't subscribed?IEnumerable result = newsItemCollection._newsItems // Filter by language: .Where(n => n.Language == language) // Take the first 5 items: ...
19 Aug 2015 by Sergey Alexandrovich Kryukov
Please see my comment to the question. Yes, this is interface, and no, people don't use it as a class, it's impossible.My idea is that you only think that some "use it as a class", because you don't know how interfaces are used and how inheritance works. A variable or a member can have...
22 Sep 2016 by Maciej Los
I'm not sure i understand you well...I'd prefer to use Linq To Xml[^].//define search criteriastring searchterm = "private";StringComparison comparison = StringComparison.InvariantCulture;//create instance of XDocumentXDocument xdoc = Xdocument.Load("FullFileName");//define...
6 Apr 2017 by Karthik_Mahalingam
it should be aRepeater.DataSource = cg.Values; since Values property gives the List which is of type IEnumerable interface
29 Apr 2018 by Eric Lynch
You're biggest problems are with the AppointmentReasonList and ReasonCodeList classes. In your JSON document, these are represented as collections. However, since both classes simply implement IEnumerable{T}, there is no way the de-serializer can add elements to the collection. Consider...
9 Jun 2023 by Graeme_Grant
That is correct, IEnumerable does not support Count property. IEnumerable only supports iteration of collections. You do need to cast to a type that supports that property. The ICollection Interface (System.Collections.Generic) | Microsoft...
8 Nov 2011 by Kabwla.Phone
Implemented with a queue and some newfangled yields.Since a queue does not have an 'EnqueueRange', we will still have to do a loop. Of course, enqueue range would be a nice extension method.Excusing the overhead created by the yield, this might use less memory if there are many controls. (Or...
24 Feb 2012 by mohammadghaderian.bp
I have a big problem. When i bind a IEnumrable object to datagridview in winForm, I can not sort it by clicking on column header . But when I bind a DataTable object, I can sort it ?How can I solve this problem without converting my IEnumrable object to datatable ??Thanks a lot.
24 Feb 2012 by OriginalGriff
I don't know why, but it is true: if you use a List as the DataSource of the DataGridView, sorting is disabled - I suspect it is something to do with IListSource but I don't know.You could convert your IEnumerable to a DataTable just for the DataGridView, there is a Tip here which provides a...
23 Jan 2013 by prabusuccess
I have to compare the IEnumerable data from UI and the IEnumerable data from SQL Server 2008 and have to insert/update the new elements from UI to DB and delete the elements from DB based on UI data. I am having Distribution_X_ListType table in DB as: DistributionID ListTypeID...
20 Feb 2013 by Mike-MadBadger
OK, I cannot get my head around the whether there is a difference between the 'classic' (perhaps long winded) way of doing it, multiple classes and the 'new' Yield route to (apparently) the same end.I can understand the classic route (I think), see the code below.Yield confuses the heck...
18 Aug 2013 by Mike-MadBadger
If anyone ever stumbles into this then I ended up answering my own question, yes yield is a very quick and easy shortcut to writing your own enumerator and in the majority of cases is probably at least as effective. The compiler simply turns yield into very similar code to that which it creates...
29 Aug 2013 by TheUltimateDebugger
IEnumerable is an interface - you can't create an IEnumerable, but rather must create some class that implements IEnumerable
14 Jan 2014 by ASP.NET Community
The iterator pattern’s role is to provide a way to access aggregate objects sequentially without the knowledge of the structure of the aggregate. The
17 Mar 2014 by Grant Weatherston
Hi peeps, i've got an IEnuermerable documents, i'm wanting to sort this IEnumerable by a custom order, of TypeIdnow i know could do documents.OrderBy(d => d.Type.Id) but i'm dont want it to order 1-5 etc, i would like a custom order of type.Id as following3,5,2,4,6 (this is a button...
3 Oct 2014 by Grant Weatherston
Hi Guys i'm wanting a simple and quick way (without having to use two foreach loops) to retrieve objects that match my criteria:I have a IEnumerable currentNews;a NewsItem object has a property of IEnumberable;inside the Subscribers objects there is a property of Id;i would like to...
27 Jul 2015 by Member 11866351
Hi ,I have to populate **distinct** company name in Dropdownlistfor from @model IEnumerableI tried the following way. Nothing is working. Your help is appreciated.1. @Html.DropDownListFor(Model.Select(i => i.CompanyName).Distinct().ToList(), new List(), new { @class...
27 Jul 2015 by Richard Deeming
Try something like this:@Html.DropDownListFor(model => model.CompanyName, new SelectList(Model.Select(i => i.CompanyName).Distinct()), new { @class = "input-large form-control" })
5 Nov 2015 by Member 11589472
Front end( what else i have to right in the front page according to dynamic upadte from stored procedure )--------------------------------------------------------------------------------------------------------------------------------------------
5 Nov 2015 by Naz_Firdouse
You are trying to enable a series before adding it to chartMove the line chtCampaignHits.Series[s].Enabled = true;next to chtCampaignHits.Series.Add(new Series(s));Your code should be chtCampaignHits.Series.Add(new Series(s));chtCampaignHits.Series[s].Enabled =...
6 Jul 2016 by Maciej Los
I'd suggest to read this very interesting article comes from CP Knowledge Base: IEnumerable  Vs IQueryable[^]Other resources:c# - Returning IEnumerable vs IQueryable - Stack Overflow[^]linq - What's the difference between IQueryable and IEnumerable - Stack Overflow[^].net - What...
12 Apr 2017 by RjBFlorida
Not clear why following code returns "A valid data source must implement either IListSource or IEnumerable" public class CGroup { public TKey Key { get; set; } public IEnumerable Values { get; set; } } //AIT is declared class var cg = new CGroup();...
12 Apr 2017 by RjBFlorida
Unfortunately, I couldn't find the solution for this so instead of trying to create an empty datasource with a key value (was hoping the key value would display "empty" in the list), I instead set the datasource to null and used labels to display "empty".
28 Apr 2018 by Member 13801974
Hello, I've been wrangling with deserializing a certain json snippet into an object that deploys the IEnumerable interface so I can loop through its list and use some of its attributes as parameters in a SQL query. I already received a few answers that didn't solve the problem. You can view...
13 Jun 2018 by Member 13871081
I am hoping I can get some insight to a issue I have been struggling to resolve. I am new to c# Nunit and Visual studio. I have an XML storing usernames and XML storing passwords and .resx file in Visual Studio storing all the browser names. Every password and username has to be parallel tested...
28 Mar 2019 by prapti.n3
I have a Chart class as following: private Int32 _id = 0; public Int32 id { get { return _id; } set { _id = value; } } private string _name = string.Empty; public string name { get { return _name; }...
28 Mar 2019 by #realJSOP
Google (or in my case, DuckDuckGo) is FULL of links: json to datatable at DuckDuckGo[^]
19 Apr 2019 by Member 13486725
I'm new to both MVC and LinqToSql. I'm trying to create a small application that lists contacts using both technologies. What I have tried: My Model: public class Contact { [Key] public int Id { get; set; } [Required] public string Name { get; set; } ...
19 Apr 2019 by Dave Kreskowiak
Well, since IList implements IEnumerable, you should be good there. But, you didn't really read the error message. You apparently have two different Contact classes. once in a namespace called ContactsApp and the other in a namespace called ContactsApp.Models. The two are not interchangeable. ...
24 Apr 2019 by Jihed Haj Ali
You can use sites like quicktype to generate your code from your JSON data. // // // To parse this JSON data, add NuGet 'Newtonsoft.Json' then do: // // using QuickType; // // var welcome = Welcome.FromJson(jsonString); namespace QuickType { using System; using...
28 Jan 2020 by Member 14103699
Hi All, I have a class like below class Test { public long TEstId{ get; set; } public IEnumerable OrderChanges { get; set; } } When am passing the data as below to above model, ienumberable property returns null { ...
28 Jan 2020 by OriginalGriff
C# supports Tuples, but ... JSON doesn't have a tuple indicator, so it "does the best it can" and generates a type that isn't a tuple. If I correct the JSON (by removing the space from the name "OrderChanges ") and run it through a JSON class generator[^] you get this: public class OrderChange...
28 Jan 2020 by F-ES Sitecore
I'm amazed you found no useful information about how to deserilise JSON, there are lots of articles. public class OrderChange { public long item1 { get; set; } public long[] item2 { get; set; } } public class Test { public long TEstId { get; set; } public...
29 Jul 2020 by Bullgill Coder
I am fairly new to APIs and I am trying to run a query that will always just return 1 result. I have some code that works but it is using List so when the JSON is returned I get square brackets, eg. [ { "customer": 43563254, ...
11 Jun 2023 by Richard Deeming
The only way Count() or ToList() will throw an InvalidCastException is if you have a source list which contains values of different types, and you've used Cast to treat it as a list of a single type. * List source = new...
2 Nov 2023 by Mike-MadBadger
This is an alternative for "Pick Your Enumerator & Me.Understand Yield and IEnumerable (C#)"
25 Jan 2016 by GravityPhazer
This article demonstrates how you can simply enumerate any generic tree depth-first as well as breadth-first using the described construct. Trees can be serialized binary (using the BinaryFormatter), custom binary and as XML.
26 Aug 2018 by WyoMetz
Simple and easy paging of a WPF DataGrid with DataTable and LINQ queries
26 Jan 2016 by Jörgen Andersson
A propertymapping extension for DataReaders
18 Jan 2012 by wgross
I would just use:string.Join(",", cities.Select(c=>c.Name))Since Version 4 of the Framework there is an overloaded versions of string.Join for IEnumerable too. It uses a StringBuilder internally and doesn't insert a seperator after the last element as well.I could't find the Join method...
5 Sep 2012 by interopper
How to make a thin-as-possible .NET IEnumerable-wrapper around MFC list classes.
24 Jan 2012 by Mikhail-T
A short one-line way to convert Array or List of any data into custom string via LINQ
21 Apr 2013 by Mike-MadBadger
Using multiple enumerators and implementing IEnumerable with Yield or IEnumerator.
9 Jun 2023 by OriginalGriff
That's not what I get: List itemsAsList = new List { "one", "two", "three" }; IEnumerable items = itemsAsList; int count = items.Count(); Console.WriteLine(count); ...
14 Dec 2015 by dibley1973
This morning at work a colleague and myself discovered a slightly alarming difference between `IEnumerable.ForEach` and `List.ForEach` when we switched a collection type for a field in a C# ASP.NET MVC project.
5 Jun 2022 by Ramesh Bevara
An overview of a helper class to build dynamic order by clause in LINQ query in C#
20 Nov 2012 by koleraba
HiI have a few general questions about IEnumerable. I know that it uses deferred execution i.e. it is only executed when it needs to be. What I don't know is when is best to use IEnumerable as a method parameter.Let say I have a method that reads from an xml file and returns an...
20 Nov 2012 by Sergey Alexandrovich Kryukov
The main reason to develop any type implementing System.Collections.IEnumerable, http://msdn.microsoft.com/en-us/library/system.collections.ienumerable.aspx[^], is to introduce the possibility of traversing some set of objects through forеаch...
18 Jan 2014 by AlexHarmes
I have a ViewModel; public class GetQuestionViewModel { public IEnumerable Questions { get; set; } public IEnumerable QuestionOptions { get; set; } public int Id { get; set; } public Nullable Options { get; set; } ...
21 Sep 2017 by Richard Deeming
You don't need to map the member; you just need to map both types. Given: namespace Db { public class Order { public List Ship { get; set; } } public class ShipOnly { public string Name { get; set; } } } namespace Dto { public...
24 Jan 2012 by Richard Deeming
If you're stuck with .NET 3.5, you can use the Aggregate extension method[^]:string cities_string = cities.Aggregate(new StringBuilder(), (sb, c) =>{ if (0 != sb.Length) sb.Append(", "); sb.Append(c.Name); return sb;}, sb => sb.ToString());
24 Apr 2019 by Member 14202729
Hello folks, The exception I'm getting is as follows: "Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.IEnumerable`1 because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\nTo fix this error either change...
19 Aug 2015 by Jethro Daniel
I am a beginner c# developer. I converted from php to c# recently. From my previous knowledge, and the one I acquired while learning c#.. I know interface contain method definitions and other property definitions. But I constantly see people using the Ienumerable interface like a class. This is...
14 Dec 2016 by Member 12724052
Just what the title says. I will attach a gif here. to show you what exactly I mean. without running into outofmemoryexceptionWhat I have tried:........
29 Aug 2013 by christhuxavier
hi, usually if we want use Inumerable, we will use follows.class program{static void main(string[] args){List oyears=new List();oyears.Add(100);oyears.Add(101);oyears.Add(102);}IEnumerable enum=(IEnumerable) oyears;foreach(int i...
23 Jan 2013 by dan!sh
You must be having a concrete class that implements the interface. You will have to create object of that class and add data to it. This object can then be added to the interface list you have.
17 Mar 2014 by phil.o
You could try to implement a custom IComparer{ public int Compare(int left, int right) { int result; if (left == right) { result = 0; } if (left == 3) { result = 1; } ...
27 Jul 2015 by Member 11866351
I tried and got the following error:CS1061: 'System.Collections.Generic. CS1061: 'System.Collections.Generic.IEnumerable'does not contain a definition for 'CompanyName' and no extension method 'CompanyName' accepting a firstargument of type...
6 Jul 2016 by super_user
can anyone please explain this in simple wordsIQueryableandIEnumerableWhat I have tried:i.e. for examplewhat is the difference between these 3 IEnumerable scoreQuery = //query variable from score in scores //required where score > 80 // optional ...
22 Sep 2019 by Samps Pro
I'm developing the master detail data entry form without using entity framwork. I have two tables deal making and deal details for this purpose I pass the values of master and detail to the controller using ajax call. its going well and all records are coming in the controller I check it by...
11 Jun 2023 by Le lance Flamer
Hello, I got another weird issue in C# where the method "Count" of IEnumerable and the "Count" property of List raises an InvalidCastException. I may not be very clear about this issue so I'll show you the piece of code where the exception is...
21 Sep 2017 by Member 13229879
I want to map list of Dto to other object to using Automapper Source: public class Order { public List Ship { get; set; } } public class ShipOnly { public string Name { get; set; } } Destination public class Order { public...