IEnumerable<IEnumerable<T>> to IEnumerable<T> using LINQ
How to split an IEnumerable of IEnumerables to one flat IEnumerable using LINQ (or someway else)? ...
How to split an IEnumerable of IEnumerables to one flat IEnumerable using LINQ (or someway else)? ...
I could do this using loops, but is there a way to take two IEnumerables, enumerate through all possible permutations and select an object that contains the permutation? I feel like this 'should' be possible but am not really sure what operators to use. Thanks James ...
Why in this example from MSDN, in GetEnumerator method, PeopleEnum returns IEnumerator? public class Person { public Person(string fName, string lName) { this.firstName = fName; this.lastName = lName; } public string firstName; public string lastName; } public class People : IEnumerable { privat...
But some of the callers is the Dictionary's TryGetValue and ContainsKey and so require the result of the method to be a Dictionary, how can I convert the IEnumerable<KeyValuePair<string, ArrayList>> into a Dictionary<string, ArrayList> so that I can use TryGetValue ? I've a method which at present returns an IEnumerable<KeyValuePair<str...
I am parsing an arbitrary length byte array that is going to be passed around to a few different layers of parsing. Each parser creates a Header and a Packet payload just like any ordinary encapsulation. And my problem lies in how the encapsulation holds its packet byte array payload. Say i have a 100 byte array, and it has 3 levels of e...
Hi all, I wrote a method which exports values to excel file from an IEnumerable parameter. Method worked fine for my little test class and i was happy till i test my method with a LINQ class. Method: public static void IEnumerableToExcel<T>(IEnumerable<T> data, HttpResponse Response) { Response.Clear(); Response.Co...
Is there any method / extension method on IEnumerable that allows me to find the index of of an object instance in it? Like IndexOf() in IList? indexPosition = myEnumerable.IndexOf() ? Thanks ...
I was wondering how could I improve the performance of the following code: public class MyObject { public int Year { get; set; } } //In my case I have 30000 IEnumerable<MyObject> data = MethodThatReturnsManyMyObjects(); var groupedByYear = data.GroupBy(x => x.Year); //Here is the where it takes around 5 seconds foreach (var gro...
I am using Linq to query my database and returning a generic IList. Whatever I tried I couldn't convert an IQueryable to an IList. Here is my code. I cannot write simpler than this and I don't understand why it is not working. public IList<IRegion> GetRegionList(string countryCode) { var query = from c in Database.RegionDataSour...
So, this question was just asked on SO: http://stackoverflow.com/questions/2740001/how-to-handle-an-infinite-ienumerable My sample code: public static void Main(string[] args) { foreach (var item in Numbers().Take(10)) Console.WriteLine(item); Console.ReadKey(); } public static IEnumerable<int> Numbers() { int x =...
If I can implicitly cast an integer value to a double (and vice versa), like: int a = 4; double b = a; // now b holds 4.0 Why can I not do this: int[] intNumbers = {10, 6, 1, 9}; double[] doubleNumbers2 = intNumbers.Cast<double>().ToArray(); I get a "Specified cast is not valid" InvalidCastException exception. Doing the op...
I have this method (simplified): void DoSomething(IEnumerable<int> numbers); And I invoke it like this: DoSomething(condition==true?results:new List<int>()); The variable results is formed with a LINQ select condition (IEnumerable). I was wondering is this List<int>() the best way (the fastest?) to pass an empty collection, or is ...
I was implementing my own ArrayList class and was left surprised when I realised that public System.Collections.Generic.IEnumerator<T> GetEnumerator() { return _array.GetEnumerator(); } didn't work. What is the reason arrays don't implement IEnumerator in .NET? Is there any work-around? Thanks ...
I have a class that contains a static number of objects. This class needs to be frequently 'compared' to other classes that will be simple List objects. public partial class Sheet { public Item X{ get; set; } public Item Y{ get; set; } public Item Z{ get; set; } } the items are obviously not going to be "X" "Y" "Z", those are just...
Background Working in .NET 2.0 Here, reflecting lists in general. I was originally using t.IsAssignableFrom(typeof(IEnumerable)) to detect if a Property I was traversing supported the IEnumerable Interface. (And thus I could cast the object to it safely) However this code was not evaluating to True when the object is a BindingList<T>. ...
Example: System.Web.Security.MembershipCollection implements IEnumerable and not IEnumberable<T>. Why doesn't it implement the latter, when it seems that it would be better (e.g. use LINQ)? Or, is it not necessarily better? ...
I have a System.Collections.Generic.Dictionary<string, string> containing control ID and appropriate data column to data bind: var dic = new Dictionary<string, string> { { "Label1", "FooCount" }, { "Label2", "BarCount" } }; I use it that way: protected void FormView1_DataBound(object sender, EventArgs e) { var row = ((Dat...
I've got an interresting problem: Given an IEnumerable<string>, is it possible to yield a sequence of IEnumerable<string> that groups identical adjacent strings in one pass? Let me explain. 1. Basic illustrative sample : Considering the following IEnumerable<string> (pseudo representation): {"a","b","b","b","c","c","d"} How to get...
If I am walking through an IEnumerable<T>, is there any way to get a new IEnumerable<T> representing the remaining items after the current one. For example, I would like to write an extension method IEnumerator<T>.Remaining(): IEnumerable<int> sequence = ... IEnumerator<int> enumerator = sequence.GetEnumerator(); if (enumerator.MoveNe...
I've got this XML: <BillingLog> <BillingItem> <date-and-time>2003-11-04</date-and-time> <application-name>Billing Service</application-name> <severity>Warning</severity> <process-id>123</process-id> <description>Timed out on a connection</description> <detail>Timed out after three retries.</detail> </BillingI...