ilist

Is it common (or encouraged) practice to overload a function to accept IEnumerable<T>, ICollection<T>, IList<T>, etc.?

EDIT: From the answers given, it's been made rather clear to me how the design I'm asking about below should actually be implemented. With those suggestions in mind (and in response to a comment politely pointing out that my example code does not even compile), I've edited the following code to reflect what the general consensus seems t...

C# Beginner: Where has my IList.Where() method gone?

Hi guys I've got another simple one (I think) that's stumping me. I have written a method in one of my controls that gets the latest version of a file in a CMS given it's filename (i.e. regardless of what folder the file resides in). I found it useful enough that I thought I'd chuck it in my CMSToolbox class, but when I do this I can no...

c# - How to deserialize a generic list<T> when I don't know the type of (T)?

Hi, for auditory reasons I stores the arguments of the business methods serialized into the database using the binaryformatter. The problem is that when an argument is a generic list I don't find the way to cast the deserialized object because I don't know the type, or If I will know the type I don't know how to cast the object at runt...

IList stored in Session is updated when local copy of the IList is changed.

Hi, I am building a large, multi-area MVC project. (MVC 2 Beta). I have a session wrapper class, in its own project, MySession, that looks like this: Public Class MySession Private Shared _userlist As String = "UserList" Public Shared Property UserList() As IList Get If HttpContext.Current.Session(_userlist) Is Nothing ...

Cast an IList to an IList<t> using dynamic instantiation

I am try to convert the following NHibernate query using dyanmic instantiation into an IList<t> rather than an IList. IList<AllName> allNames = (IList<AllName>)Session.CreateQuery( @"select new AllName( name.NameId, name.FirstName, origin.OriginId, origin.Description, name.Sex, name.Description, name.SoundEx ) from Name name j...

Conversion of IEnumerable<T> to IList

If a method takes a parameter of type System.Collections.IList can I legitimately/safely pass a value of type System.Collections.Generic.IEnumerable<T>? I would appreciate a thorough explanation of why this is possible and what actually happens to the object T when the IEnumerable<T> is used inside of the method. Is it converted to t...

Why is there no IArray(T) interface in .NET?

Question (in short): I asked why .NET has IList<T>, which implements ICollection<T> and therefore provides methods to modify the list (Add, Remove, etc.), but doesn't offer any in-between interface such as IArray<T> to provide random access by index without any list modification. EDIT 2010-Jan-21 2:22 PM EST: In a comment to Jon Skeet...

ASP.NET MVC 2: What does the C# View look like that edits nested Entities?

I tried numerous times over the last few weeks to get a server side MVC 2 view to work with objects with nested IList elements without much success. I am missing some fundamental understanding that I hope this question resolves. What I want is a form that shows a list of product where you can change information in-line, including a hie...

Memory Leak in large Array - Will subclassing IList fix it?

I need to improve memory performance on my application and I could see that I have problems with memory fragmentation. I've read an interesting article on large objects from Andrew Hunter of Red Gate, and one of the solutions he recommends is: If large data structures need to live for a long time, and especially if they need to ...

Why is the SortedList(TKey,TValue).Keys property an IList(TKey) rather than a ReadOnlyCollection(TKey)?

The IList<T> interface includes access by index in addition to operations not supported by the SortedList<TKey, TValue>.Keys property such as Add, Remove, and Insert. A ReadOnlyCollection<T>, such as the return value of List<T>.AsReadOnly, implements IList<T> and therefore offers access by index but hides illegal operations like Add, et...

Why IList<> has less feature than List<>?

To use such great function as ConvertAll(), I have to convert IList to List, it's painful. ...

Does casting an IList<T> to an array of type T[] cause enumeration?

I have a method that looks like: T[] field; public Method(IList<T> argument) { this.field = (T[])argument; } When the body of the method is executed does enumeration take place during the cast? Would that change if the underlying type was different? ...

Should I use an ArrayList or IList

Im using the .NET framework 1.1 and Im hoping someone could help me implement a dynamic array of objects? A watered-down example of the object I wish use is below. Class CarObj { public string CarName; public string CarYear; } Should I use an ArrayList or do you think it would be better to make a CarList class to implement an...

Convert From Custom List to List of String

Hi all I have the following code: Public Shared Function ConvertToString(ByVal list As IList) As String Dim strBuilder = New System.Text.StringBuilder() Dim item As Object For Each item In list strBuilder.Append(obj.ToString()) strBuilder.Append(",") Next Return strBuil...

XmlSerializer (c#) reports There was an error reflecting type (type = List<myclass> )

Hi there, Can anyone help? I have a method for converting an object to a dataset. In this case the object is a collection (using LIST) of a a collection class Here is the code but it errors with the following error on the line XmlSerializer formatter= ... This is the error There was an error reflecting type 'System.Collections.Gener...

How do you work with IList<> in F#?

I have a list of type IList<Effort>. The model Effort contains a float called Amount. I would like to return the sum of Amount for the whole list, in F#. How would this be achieved? ...

Limited IList<> implementation ?

Hello people, I'm doing some work with stats, and want to refactor the following method : public static blah(float[] array) { //Do something over array, sum it for example. } However, instead of using float[] I'd like to be using some kind of indexed enumerable (to use dynamic loading from disk for very large arrays for example)....

Cast an IList to a Collection

I need to cast an IList to a Collection (System.Collections.ObjectModel) How do you go about this? ...

NHibernate: miss data on refresh

I have a problem with entity refreshing in NHibernate. I have an entity with IList property; this property is mapped with "list" tag on hbm mapping file. Now, on maintenance window if I remove some elements from the list (without saving) and then I call NHibernate refresh to restore changes the list items, that previously I removed, ar...

How to turn bytearray into IList in Actionscript?

How to turn Array (like Camera.names) into IList (for for ex MXML s:DropDownList <s:DropDownList x="113" y="121" selectedIndex="0" dataProvider="{Camera.names}"></s:DropDownList> )? ...