ilist

Sorting an IList in C#

So I came across an interesting problem today. We have a WCF web service that returns an IList. Not really a big deal until I wanted to sort it. Turns out the IList interface doesn't have a sort method built in. I ended up using the ArrayList.Adapter(list).Sort(new MyComparer()) method to solve the problem but it just seemed a bit "gh...

Binding Gtk# NodeView to a IList?

I've got a data object with a component in it that is an System.Collections.Generic.IList, and I'd like to reflect changes to that list into a Gtk# NodeView, so that when an item is added to the list, the NodeView will get a new item added to it. How would I listen for changes to an IList? I have considered wrapping the IList with a ...

Data Access Layer: Exposing List<>: bad idea?

Hi everyone, I am currently coding a simple Data Access Layer, and I was wondering which type I should expose to the other layers. I am going to internally implement the Data as a List<>, but I remember reading something about not exposing the List type to the consumers if not needed. public List<User> GetAllUsers() // non C# users: t...

C# Syntax - Split String into Array by Comma, Convert To Generic List, and Reverse Order

What is the correct syntax for this: IList<string> names = "Tom,Scott,Bob".Split(',').ToList<string>().Reverse(); What am I messing up? What does TSource mean? ...

IList vs IEnumerable for Collections on Entities

When I have entities in my domain with lists of things, should they be exposed as ILists or IEnumerables? E.g. Order has a bunch of OrderLines. ...

C# - List<T> or IList<T>

Can anyone explain to me why I would want to use IList over List in C#? Related question: Why is it considered bad to expose List<T> ...

Should I return IList or List to the Controller in MVC ?

What is difference to the controller that gets the return with repect to rendering the List? In Linq dataContext: public IList<Response> GetResponses(int ID) { var responses = from r in this.Responses where r.ID == ID orderby r.Date select r; return responses.ToList(); } OR public List<Response> GetResponse...

FindLast on IEnumarable

I would like to call FindLast on a collection which implements IEnumarable, but FindLast is only available for List. What is the best solution? ...

PropertyGrid - Ilist Collection Remove not firing as expected

I have a collection object that implements IList. Inside the collection I have used a List to collect the items. Inside the PropertyGrid (at runtime), it binds properly and the Collection Editor opens. I can edit, and I can add items properly and I can catch these methods when they are used in the collection class. However, if you try t...

Dynamically creating a new instance of IList's type

Hi, My application is processing IList's. ILists of different user defined types. I'm thinking that i can use reflection to to see what type of object the IList contains and then create a new instance of that type and subsequently add that to the IList itself? So at any one time I might be processing IList<Customer> l; and I'd like ...

How do I get all the values of a Dictionary<TKey, TValue> as an IList<TValue>?

I have a the following dictionary: IDictionary<int, IList<MyClass>> myDictionary and I am wanting to get all the values in the dictionary as an IList.... Just to add a bit of a background as to how I've gotten into this situation.... I have a method that gets me a list of MyClass. I then have another method that converts that list...

How do I perform a FindAll() on an IList<T>? (eg. SortedList.Values)

I'm working on a problem in C# 2.0/.NET 2.0 where I have a Sortedlist and want to search all the "values" (not the "keys") of this SortedList for a certain substring and count up how many occurrences there are. This is what I'm trying to do: { Sortedlist<string,string> mySortedList; // some code that instantiates mySortedList and...

Linq Select IList

List<MyParentClass> parents = new List<MyParentClass>(); var parent1 = new MyParentClass("parent1"); var parent2 = new MyParentClass("parent2"); parents.Add(parent1); parents.Add(parent2); var child1 = new MyChildClass("child1"); parent1.children.Add(child1); var child2 = new MyChildClass("child2"); va...

Unittesting IList with CollectionAssert

The mstest framework has a CollectionAssert that accepts ICollections. My method returns an IList. Apparantly a list is not a collection.. Are there ways to make my IList an ICollection? ...

Best string container: StringCollection, Collection<string>, List<string>, ArrayList, .. ?

What is the most suitable container just for strings holding in some array with non-predetermined upper boundary, which length is unknown on it's creation. For simple code like: Foo list = new Foo(); // size in unknown for()/foreach()/do()/while() // any loop { list.Add(string); } Is it StringCollection as optimized Collection for ...

C# - Reflection using Generics: Problem with Nested collections of ILists

Hi Everyone, I would like to be able to print object properties, and I've hit a snag when I hit nested collections of the iLists. foreach (PropertyInformation p in properties) { //Ensure IList type, then perform recursive call if (p.PropertyType.IsGenericType) { ...

Why is .ForEach() on IList<T> and not on IEnumerable<T>?

I've noticed when writing LINQ-y code that .ForEach() is a nice idiom to use. For example, here is a piece of code that takes the following inputs, and produces these outputs: { "One" } => "One" { "One", "Two" } => "One, Two" { "One", "Two", "Three", "Four" } => "One, Two, Three and Four"; And the code: private string InsertCommasAt...

IList(Of T).Sort help

Dim classCodeDetails As List(Of ClassCodeDetail) = db.ClassCodeHeaders.Single(Function(cch) cch.CLCH_ID = classCodeHeaderId ).ClassCodeDetails.ToList() classCodeDetails.Sort(Function(c1, c2) c1.Make.MAKE_English.CompareTo(c2.Make.MAKE_English) ) My question is how can I sort on multiple attributes? I want to...

Why does casting List<T> into IList<T> result in reduced performance?

I was doing some performance metrics and I ran into something that seems quite odd to me. I time the following two functions: private static void DoOne() { List<int> A = new List<int>(); for (int i = 0; i < 200; i++) A.Add(i); int s=0; for (int j = 0; j < 100000; j++) { f...

Which interface should I expose a List<T> via?

In a response to this question runefs suggested that "unless you have a very specific reason for using IList you should considere IEnumerable". Which do you use and why? ...