ienumerable Questions

4

Solved

Does C# offer some nice method to cast a single entity of type T to IEnumerable<T>? The only way I can think of is something like: T entity = new T(); IEnumerable<T> = new List { enti...
Uis asked 10/2, 2011 at 16:51

4

Solved

Why cant I use an IEnumerable with params? Will this ever be fixed? I really wish they would rewrite the old libraries to use generics...
Clinic asked 24/1, 2010 at 20:49

5

Solved

How to iterate over items in a Tuple, when I dont know at compile-time what are the types the tuple is composed of? I just need an IEnumerable of objects (for serialization). private static IEnume...
Coprology asked 11/4, 2017 at 8:56

4

Solved

I have a class of User, which can have several contact numbers. I am using CsvHelper to generate a report on the users, which will create a CSV file of the User's name and contact details. Each con...
Gaddis asked 16/6, 2015 at 8:49

23

Solved

private IEnumerable<string> Tables { get { yield return "Foo"; yield return "Bar"; } } Let's say I want iterate on those and write something like processing #n of #m. Is there a way ...
Malleolus asked 3/10, 2008 at 21:5

6

Solved

OK, so List<> contains the AsReadOnly() which gives you the ReadOnlyCollection. What I need is to have a field of IList type, and a property which would return a ReadOnlyCollection for this list...
Duax asked 29/8, 2011 at 8:6

6

Solved

I have an IEnumerable<T>. I want to do one thing for each item of the collection, except the last item, to which I want to do something else. How can I code this neatly? In Pseudocode foreac...
Tritanopia asked 24/5, 2012 at 10:32

7

Solved

I have two instances of IEnumerable<T> (with the same T). I want a new instance of IEnumerable<T> which is the concatenation of both. Is there a built-in method in .NET to do that or do...
Delois asked 4/1, 2013 at 21:7

13

Solved

I wrote this: public static class EnumerableExtensions { public static int IndexOf<T>(this IEnumerable<T> obj, T value) { return obj .Select((a, i) => (a.Equals(value)) ? i : -1...
Exchangeable asked 17/8, 2009 at 21:37

10

Solved

Is there a built in LINQ method thing I can use to find out if two sequences contains the same items, not taking the order into account? For example: {1, 2, 3} == {2, 1, 3} {1, 2, 3} != {2, 1...
Rakel asked 10/3, 2009 at 13:52

13

What is the difference between IQueryable<T> and IEnumerable<T>? See also What's the difference between IQueryable and IEnumerable that overlaps with this question.
Craze asked 31/10, 2008 at 7:18

4

Solved

I only watched a few webcasts before I went head first in to designing a few Entity Framework applications. I really didn't read that much documentation and I feel like I am suffering for it now. I...
Reynoso asked 5/10, 2011 at 1:33

4

Is there an easy way to convert an IEnumerable to TheoryData? For example, if I want to pass the set of enumeration options, I'm looking for something like: IEnumerable<TheoryData<MyEnum>&...
Midsummer asked 4/8, 2022 at 0:38

8

Solved

I know it's possible to cast a list of items from one type to another (given that your object has a public static explicit operator method to do the casting) one at a time as follows: List<Y>...
Swat asked 25/2, 2011 at 8:51

12

Solved

I am trying to do something like this: image.Layers which returns an IEnumerable<Layer> for all layers except the Parent layer, but in some cases, I just want to do: image.Layers.With(image....
Swedenborgianism asked 3/2, 2011 at 19:8

4

Solved

Let's say I for example have this class that generates Fibonacci numbers: public class FibonacciSequence : IEnumerable<ulong> { public IEnumerator<ulong> GetEnumerator() { var a = 0U...
Braud asked 2/10, 2009 at 14:54

5

Solved

Given two IEnumerables of the same size, how can I convert it to a Dictionary using Linq? IEnumerable<string> keys = new List<string>() { "A", "B", "C" }; IEnumerable<string> val...
Disrespectable asked 28/10, 2010 at 1:14

6

Solved

I have an optional parameter of type IEnumerable<int> in my C# method. Can I initialize it with anything but null, e.g. a fixed list of values?
Birdcage asked 10/1, 2013 at 9:56

6

Solved

I am having a Text Like var data = "âô¢¬ôè÷¢ : ªîø¢è¤ô¢ - ã¿ñ¬ô ñèù¢ ªð¼ñ£÷¢ ï¤ôñ¢,«ñø¢è¤ô¢ - ªð¼ñ£÷¢ ñèù¢ ÝÁºèñ¢ ï¤ô袰ñ¢ ñ¤ì¢ì£ Üò¢òñ¢ ªð¼ñ£ñ¢ð좮 è¤ó£ñ âô¢¬ô袰ñ¢,õìè¢è¤ô¢ - ÝÁºèñ¢ ï¤ôñ¢,è¤...
Blinders asked 23/8, 2013 at 6:26

20

Solved

Is there a common way to pass a single item of type T to a method which expects an IEnumerable<T> parameter? Language is C#, framework version 2.0. Currently I am using a helper method (it's...
Shult asked 16/10, 2009 at 12:40

15

If I have an IEnumerable like: string[] items = new string[] { "a", "b", "c", "d" }; I would like to loop thru all the pairs of consecutive items (sliding w...
Purlin asked 23/2, 2009 at 13:17

24

Solved

I found an example in the VS2008 Examples for Dynamic LINQ that allows you to use a SQL-like string (e.g. OrderBy("Name, Age DESC")) for ordering. Unfortunately, the method included only ...
Lavender asked 3/9, 2008 at 6:30

24

Solved

I found an example in the VS2008 Examples for Dynamic LINQ that allows you to use a SQL-like string (e.g. OrderBy("Name, Age DESC")) for ordering. Unfortunately, the method included only ...
Hawfinch asked 3/9, 2008 at 6:30

24

Solved

I found an example in the VS2008 Examples for Dynamic LINQ that allows you to use a SQL-like string (e.g. OrderBy("Name, Age DESC")) for ordering. Unfortunately, the method included only ...
Troglodyte asked 3/9, 2008 at 6:30

6

Solved

I could not find a related question. In python you can easily loop through a sequence (list, generator etc) and collect the index of the iteration at the same time thanks to enumerate(seq) like th...
Ointment asked 12/9, 2011 at 13:56

© 2022 - 2024 — McMap. All rights reserved.