ilist

Which Json deserializer renders IList<T> collections?

六眼飞鱼酱① 提交于 2019-12-03 04:01:58
I'm trying to deserialize json to an object model where the collections are represented as IList<T> types. The actual deserializing is here: JavaScriptSerializer serializer = new JavaScriptSerializer(); return serializer.Deserialize<IList<Contact>>( (new StreamReader(General.GetEmbeddedFile("Contacts.json")).ReadToEnd())); Before i post the exception i'm getting you should know what the implicit conversions are. This is the Contact type: public class Contact { public int ID { get; set; } public string Name { get; set; } public LazyList<ContactDetail> Details { get; set; } //public List

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

断了今生、忘了曾经 提交于 2019-12-02 20:51:20
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? Well, I couldn't find such a class anywhere; so I gave it a shot . The source code for my ConcurrentList<T> class is available

Is there a limit of elements that could be stored in a List?

一世执手 提交于 2019-12-01 16:51:39
Is there a limit of elements that could be stored in a List ? or you can just keeping adding elements untill you are out of memory ? The current implementation of List<T> uses Int32 everywhere - to construct its backing array, for its Count property, as an indexer and for all its internal operations - so there's a current theoretical maximum of Int32.MaxValue items ( 2^31-1 or 2147483647 ). But the .NET framework also has a maximum object size limit of 2GB, so you'll only get anywhere near the items limit with lists of single-byte items such as List<byte> or List<bool> . In practice you'll

Is there a limit of elements that could be stored in a List?

允我心安 提交于 2019-12-01 15:37:37
问题 Is there a limit of elements that could be stored in a List ? or you can just keeping adding elements untill you are out of memory ? 回答1: The current implementation of List<T> uses Int32 everywhere - to construct its backing array, for its Count property, as an indexer and for all its internal operations - so there's a current theoretical maximum of Int32.MaxValue items ( 2^31-1 or 2147483647 ). But the .NET framework also has a maximum object size limit of 2GB, so you'll only get anywhere

Unit-testing IList with CollectionAssert

守給你的承諾、 提交于 2019-12-01 13:58:32
问题 The MSTest framework has a CollectionAssert that accepts ICollections. My method returns an IList. Apparently a list is not a collection.. Are there ways to make my IList an ICollection? 回答1: You could call the ToArray() extension method on it - Array implements ICollection Edit: Also, while List<T> implements ICollection, IList<T> only implements ICollection<T> which does not implement ICollection, so if you know the item in the test is a List<T> , you should be able to cast it... 回答2: You

.NET / C# Binding IList<string> to a DataGridView

最后都变了- 提交于 2019-12-01 04:13:30
I have an IList<string> returning from a function (as variable lst) and I set and then I this.dataGridView1.DataSource = lst; The datagrid adds one column labelled Length and then lists the length of each string. How do I make it just list the strings? You really need a list of objects that have a string property. With .NET 3.5 you could cheat: .DataSource = list.Select(x=>new {Value = x}).ToList(); Otherwise create a dummy class and copy the data in manually... This is because DataGridViews show properties of the object. In this case the List only has one property "Length", therefore it can

Why doesn't IList support AddRange

时光毁灭记忆、已成空白 提交于 2019-11-29 04:19:20
问题 List.AddRange() exists, but IList.AddRange() doesn't. This strikes me as odd. What's the reason behind this? 回答1: Because an interface shoud be easy to implement and not contain "everything but the kitchen". If you add AddRange you should then add InsertRange and RemoveRange (for symmetry). A better question would be why there aren't extension methods for the IList<T> interface similar to the IEnumerable<T> interface. (extension methods for in-place Sort , BinarySearch , ... would be useful)

convert List<List<object>> to IList<IList<object>>

这一生的挚爱 提交于 2019-11-28 18:46:43
I have written a method which is public List<List<object>> Fetch(string data) , inside I create List<List<object>> p = new List<List<object>>(); my boss now wants to return a IList<IList<object>> instead of List<List<object>> ie public IList<IList<object>> Fetch(string data) , so when I try do return (IList<IList<object>>) p; //throws an exception How do I convert List<List<object>> to IList<IList<object>> and back to List<List<object>> Thanks. You can't perform that conversion via straight casting - it wouldn't be safe. Instead, you should use: IList<IList<object>> ret = new List<IList<object

Cast IList to List

北战南征 提交于 2019-11-28 18:06:36
I am trying to cast IList type to List type but I am getting error every time. List<SubProduct> subProducts= Model.subproduct; Model.subproduct returns IList<SubProduct> . Try List<SubProduct> subProducts = new List<SubProduct>(Model.subproduct); or List<SubProduct> subProducts = Model.subproducts as List<SubProduct>; How about this: List<SubProduct> subProducts = Model.subproduct.ToList(); In my case I had to do this, because none of the suggested solutions were available: List<SubProduct> subProducts = Model.subproduct.Cast<SubProduct>().ToList(); Webleeuw List<SubProduct> subProducts= (List

Difference between IEnumerable and IEnumerable<T>?

不问归期 提交于 2019-11-28 16:39:12
What is the difference between IEnumerable and IEnumerable<T> ? I've seen many framework classes implementing both these interfaces, therefore I would like to know what advantages one get by implementing both? Please have a look how they've been defined: public interface IEnumerable { [DispId(-4)] IEnumerator GetEnumerator(); } public interface IEnumerable<T> : IEnumerable { IEnumerator<T> GetEnumerator(); } As we see, IEnumerable<T> derives from IEnumerable , that means whatever IEnumerable has, IEnumerable<T> inherits, then why do we implement both instead of just IEnumerable<T> ? Is