ilist

Dynamically creating a new instance of IList's type

懵懂的女人 提交于 2019-12-08 02:29:43
问题 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 to create a new instance of Customer Customer c = new Customer(0, "None") and then add that onto the list l.Add(c); Obviously doing this dynamically at run-time is the

Why does List<T> not implement IOrderedEnumerable<T>?

时间秒杀一切 提交于 2019-12-06 19:33:27
问题 I would like to work with ordered enumerables, and use interfaces as return types rather than the concrete types. I need to return an ordered set of objects. But, when using an IList<T> implementation I can not return IOrderedEnumerable<T> , as IList<T> does not inherit IOrderedEnumerable<T> . In the example below I have a view model with a repository of series, implemented as a List<T> of series objects, which are, as they are residing in a List<T> , ordered. I an accessor method, I want to

Two list synchronization

ε祈祈猫儿з 提交于 2019-12-06 16:08:21
I'm doing the synchronization between the two lists. IList<Event> GoogleEvents and Table<myEvent> DB.Events; On google side i'm using this String Summary, String Description, EventDateTime Start, EventDateTime End, Event.RemindersData Reminders; On db side like this my code is like this foreach (myEvent item in DB.Events) { if (item.GoogleID == "" || item.GoogleID == null)// i add event my db { //Add dbEvent to google and save id to googleid column } } foreach (Event item in myGoogleCalendar.Items) { if (DB.Events.Where(o => o.GoogleID == item.Id).Count() == 0)// i add event google { //Add

c# Update Datagridview based on IList

淺唱寂寞╮ 提交于 2019-12-06 11:57:53
I have a very simple class: People: class People { private string LastName = null; private string FirstName = null; private string Status = null; public string lastName { get { return LastName; } set { LastName = value; } } public string firstName { get { return FirstName; } set { FirstName = value; } } public string status { get { return Status; } set { Status = value; } } public People(string lastName, string firstName, string status) { LastName = lastName; FirstName = firstName; Status = status; } } And, I have another class that implements the interface IList<>, which is meant to be used

Dynamically creating a new instance of IList's type

限于喜欢 提交于 2019-12-06 04:31:43
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 to create a new instance of Customer Customer c = new Customer(0, "None") and then add that onto the list l.Add(c); Obviously doing this dynamically at run-time is the crux of the problem. Hope somebody can give me some pointers. Thanks brendan Try this: public static

Why does List<T> not implement IOrderedEnumerable<T>?

泄露秘密 提交于 2019-12-05 00:44:34
I would like to work with ordered enumerables, and use interfaces as return types rather than the concrete types. I need to return an ordered set of objects. But, when using an IList<T> implementation I can not return IOrderedEnumerable<T> , as IList<T> does not inherit IOrderedEnumerable<T> . In the example below I have a view model with a repository of series, implemented as a List<T> of series objects, which are, as they are residing in a List<T> , ordered. I an accessor method, I want to return a filtered set of the series where only series objects of a specific type are returned, while

Why does IList<T> implement IEnumerable<T> and ICollection<T> while ICollection<T> itself implements IEnumerable<T> [duplicate]

≯℡__Kan透↙ 提交于 2019-12-04 07:40:20
This question already has answers here : Why does List<T> implement IList<T>, ICollection<T> and IEnumerable<T>? (4 answers) Closed 4 years ago . Why is IList defined like this? public interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable public interface ICollection<T> : IEnumerable<T>, IEnumerable public interface IEnumerable<T> : IEnumerable Couldn't it just be public interface IList<T> : ICollection<T> So, to test I created these interfaces, just to be sure if that works! public interface IOne { string One(); } public interface ITwo : IOne { string Two(); } public interface

Must IList be finite?

允我心安 提交于 2019-12-04 01:01:12
Must .NET's IList be finite? Suppose I write a class FibonacciList implementing IList<BigInteger> The property Item[n] returns the nth Fibonacci number. The property IsReadOnly returns true. The methods IndexOf and Contains we can implement easily enough because the Fibonacci sequence is increasing - to test if the number m is Fibonacci, we need only to compute the finite sequence of Fibonacci numbers up to m. The method GetEnumerator() doing the right thing We've now implemented all the methods expected of read-only ILists except Count(). Is this cool, or an abuse of IList? Fibonacci numbers

C# chunked array

﹥>﹥吖頭↗ 提交于 2019-12-03 09:22:14
I need to allocate very large arrays of simple structs (1 GB RAM). After a few allocations/deallocations the memory becomes fragmented and an OutOfMemory exception is thrown. This is under 32 bit. I'd rather not use 64 bit due to the performance penalty I get - the same application runs 30% slower in 64 bit mode. Are you aware of some implementations of IList compatible arrays which allocate memory in chunks and not all at once? That would avoid my memory fragmentation problem. Dirk Vollmar Josh Williams presented a BigArray<T> class on his blog using a chunked array: BigArray<T> , getting

Lock free & Thread-Safe IList<T> for .NET

纵然是瞬间 提交于 2019-12-03 07:20:34
问题 Is there a lock-free & thread-safe data structure that implements IList? Naturally by lock-free I mean an implementation that makes no use of locking primitives in .NET but rather uses interlocked operations / atomic operations to achieve thread safety... There isn't one, apparently under the concurrent data structures... Has anyone seen one floating around? I've seen a java one implemented in amino-cbbs, called LockFreeVector but nothing for .NET so far. Any ideas? 回答1: Well, I couldn't find