ienumerable

Chaining IEnumerables in C#?

Is there a simple built-in way to take an ordered list of IEnumerables and return a single IEnumerable which yields, in order, all the elements in the first, then the second, and so on. I could certainly write my own, but I wanted to know whether there was already a way to accomplish this seemingly useful task before I do it. ...

Creating a class to use for populating drop-down lists, grids, etc., in C#

Please keep in mind that I'm new to C# and OOP so I apologize in advance if this seems like an easy question to some. I'm going back through my code and looking for ways to objectify repetitive code and create a class for it so that I can simply reuse the class. That being said, I'm not looking to learn NHibernate or any other ORM just...

Dynamic Table Names in Linq to SQL

Hi all I have a horrid database I gotta work with and linq to sql is the option im taking to retrieve data from. anywho im trying to reuse a function by throwing in a different table name based on a user selection and there is no way to my knowledge to modify the TEntity or Table<> in a DataContext Query. This is my current code. publi...

How can I make my yielded IEnumerable work with PagedList

I'm using Troy Goode's paged List in my project. Normally you just feed it an IEnumerable, a startindex and an item count and it all works. Now however I'm trying to feed it an IEnumerable I generate as follows: private static IEnumerable<Color> GetColors(Query query) { IndexSearcher searcher = new IndexSearcher(luceneIndexpath); Hits...

Can anyone explain IEnumerable and IEnumerator to me?

Can anyone explain IEnumerable and IEnumerator to me? for example, when to use it over foreach? what's the difference between IEnumerable and IEnumerator? Why do we need to use it? ...

IEnumerable<T> provides two GetEnumerator methods - what is the difference between them?

When I emplement IEnumerable<T> interface I see two GetEnumerator methods: one returning IEnumerator and other IEnumerator<T>. When would I use one or another? ...

Best data type to store list of strings?

In .NET which data type do you use to store list of strings ? Currently I'm using List(Of String) because it's easier than Array to manage and add/remove stuff. I'm trying to understand what are the other options, when they become handy and when I should avoid List(Of String) usage. Do you use another type? Why and When? ...

Passing in <T> to a method where GetEnum<T> is called.

I’m using an API that has an object that returns IEnumerable<T>, so something like Object.GetEnum<T>. I have a method that within it will call GetEnum but I want to add to the method’s parameters the ability to pass the parameter type. So for example I want to do: private void myMethod(apiClass??? apiclass) { IEnumerable< itemTy...

Pair-wise iteration in C# or sliding window enumerator

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 window of size 2). Which would be ("a","b"), ("b", "c"), ("c", "d") My solution was is this public static IEnumerable<Pair<T, T>> Pairs(IEnumerable<T> enumerable) { ...

C# interface question

Is there a cost in passing an object to a function that implements a particular interface where the function only accepts that interface? Like: Change (IEnumerable<T> collection) and I pass: List<T> LinkedList<T> CustomCollection<T> which all of them implements IEnumerable. But when you pass any of those to the Change method, are t...

How to get a custom object out of a generic List with LINQ?

Why do I get the following error in the following code? I thought if I put custom objects in a generic List of its type then IEnumerable would be taken care of? What else do I need to do to this List to use LINQ on it? Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<TestLinq23.Customer>' to 'TestLinq23.Cus...

What is the difference between IEnumerator and IEnumerable?

What are the differences between IEnumerator and IEnumerable? ...

C# Cannot convert from IEnumerable<Base> to IEnumerable<Derived>

I recently run into trouble when trying to AddRange(IEnumerable) to a List. Probably a classic issue, but I do not really get it yet. I understand that methods expecting a List parameter are not satisfied with a List, because they might try to add a Base to the List, which is obviously impossible. But if i get this correctly, since IEn...

PrincipalSearchResult<Principal>, Lamda Expressions

Ladys and Gents, Im trying to filter out enteties from a principalcollection using what I think is called lamda expressions. I cant get this to work, I get no results. user.GetGroups() returns all the groups where user is member, but user.GetGroups().Where(....) does not return anything. Lets say that userprincipal user = Administrato...

IEnumerable.GetEnumerator() returns IEnumVariant in Delphi 6

I am using a .Net2.0 Assembly in Delphi 6 via COM. One of the methods in one of the interfaces returns IEnumerable. As long as I import mscorlib.tlb located in "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727" , I can reach both IEnumerable and IEnumerator interfaces in Delphi 6. Here is the part where IEnumerable is defined in mscorlib...

How do I merge (or zip) two IEnumerables together?

I have an IEnumerable<T> and an IEnumerable<U> that I want merged into an IEnumerable<KeyValuePair<T, U>>, where the indexes of the elements joined together in the KeyValuePair are the same. Note I'm not using IList, so I don't have a count or an index for the items I'm merging. How best can I accomplish this? I would prefer a LINQ answe...

Determine if an IEnumerable<> contains any object of another IEnumberable<> - .Net 3.5

I have 2 IEnumerable<int> IEnumerable<int> x; IEnumerable<int> y; What is the best best way to determine if any int in y is present in the x? Currently I'm using: return x.Intersect<int>(y).Count() > 0; Would it be significantly faster to loop through and test each individually? foreach (int i in x) { foreach (int j in y) ...

LINQ queries on possibly infinite lists

I am currently doing some Project Euler problems and the earlier ones often involve things like Fibonacci numbers or primes. Iterating over them seems to be a natural fit for LINQ, at least in readability and perceived "elegance" of the code (I'm trying to use language-specific features where possible and applicable to get a feel for the...

Interfaces question

I'm trying to understand the -why- of this ... and I'm really struggling to grasp the concept of what I'm telling the compiler to do when I use an IInterface syntax. Can anyone explain it in a "this is what's going on" way? Anyway ... my main question is.... What is the difference between public IEnumerable<string> MyMethod() {...} ...

IEqualityComparer.Equals when used with IEnumerable.Contains is x or y the value in the list?

IEnumberable has an extension method Contains<T> which takes two parameters. The first parameter is the value to check for and the second is an implementation of IEqualityComparer. Looking at IEqualityComparer.Equals it takes two parameters named x and y, for the first and second objects to compare. My question is X or Y the value from...