generic-list

serialize/deserialize List<T> to JSON

随声附和 提交于 2019-12-03 08:04:51
I want to be able to serialize/deserialize a generic list what I so far is this public static string ToJson(this object obj, int recursionDepth = 100) { JavaScriptSerializer serializer = new JavaScriptSerializer(); serializer.RecursionLimit = recursionDepth; return serializer.Serialize(obj); } public static List<T> ToListObject<T>(this string obj, int recursionDepth = 100) { JavaScriptSerializer serializer = new JavaScriptSerializer(); serializer.RecursionLimit = recursionDepth; List<T> returnList = serializer.Deserialize<List<T>>(obj); return returnList; } I also tried (List<T>)serializer

How to fill a DataTable with a List(Of t) or convert a List(Of t) to a DataTable?

元气小坏坏 提交于 2019-12-03 07:35:54
I have read many posts on this topic; among them and most recently .NET - Convert Generic Collection to Data Table . Unfortunately, all to no avail. I have a generic collection of structures : Private Structure MyStruct Dim sState as String Dim lValue as Long Dim iLayer as Integer End Structure Dim LOStates As New List(Of MyStruct) I need to fill a DataTable with this list of structures but have no idea how to go about doing this. I am using vb.net in Visual Studio 2008. Any insights will be greatly appreciated The code you linked assumes the members are declared as properties. You didn't

Best way to update an element in a generic List [duplicate]

半城伤御伤魂 提交于 2019-12-03 03:30:38
问题 This question already has answers here : How can I find a specific element in a List<T>? (8 answers) Closed 6 years ago . Suppose we have a class called Dog with two strings "Name" and "Id". Now suppose we have a list with 4 dogs in it. If you wanted to change the name of the Dog with the "Id" of "2" what would be the best way to do it? Dog d1 = new Dog("Fluffy", "1"); Dog d2 = new Dog("Rex", "2"); Dog d3 = new Dog("Luna", "3"); Dog d4 = new Dog("Willie", "4"); List<Dog> AllDogs = new List

Insert 6000 rows in Couchbase, but not stored success

房东的猫 提交于 2019-12-02 18:06:47
问题 I generated 6000 objects in List, and stored List into Couchbase with memcached, but the Store method returned "false" without any messages, I don't know why 6000 rows data can not be stored but 2000 rows data works. 回答1: Couchbase is not designed to store large lists of data as one object. You cannot change the 20MB limit. Therefore, to store your objects, you need to store each one separately. See here for more information. 来源: https://stackoverflow.com/questions/10679633/insert-6000-rows

Best way to update an element in a generic List [duplicate]

五迷三道 提交于 2019-12-02 16:59:43
This question already has an answer here: How can I find a specific element in a List<T>? 8 answers Suppose we have a class called Dog with two strings "Name" and "Id". Now suppose we have a list with 4 dogs in it. If you wanted to change the name of the Dog with the "Id" of "2" what would be the best way to do it? Dog d1 = new Dog("Fluffy", "1"); Dog d2 = new Dog("Rex", "2"); Dog d3 = new Dog("Luna", "3"); Dog d4 = new Dog("Willie", "4"); List<Dog> AllDogs = new List<Dog>() AllDogs.Add(d1); AllDogs.Add(d2); AllDogs.Add(d3); AllDogs.Add(d4); AllDogs.First(d => d.Id == "2").Name = "some value";

Insert 6000 rows in Couchbase, but not stored success

大憨熊 提交于 2019-12-02 12:02:23
I generated 6000 objects in List, and stored List into Couchbase with memcached, but the Store method returned "false" without any messages, I don't know why 6000 rows data can not be stored but 2000 rows data works. Couchbase is not designed to store large lists of data as one object. You cannot change the 20MB limit. Therefore, to store your objects, you need to store each one separately. See here for more information. 来源: https://stackoverflow.com/questions/10679633/insert-6000-rows-in-couchbase-but-not-stored-success

How to compare List<String> to DB Table using LINQ

最后都变了- 提交于 2019-12-02 04:07:48
I have a list<> of phone numbers and I am trying to join that with the corresponding records in the db table and get an order number and a customer ID. Also the list has the whole number as one string and the DB has it broken to area code, prefix, number each as separate fields. I am fairly new to LINQ, so this is a beyond what I currently know. Any suggestions are GREATLY appreciated. var tnbrs = new List<string>(); have tried: var tntable = tnbrs.Cast<DataSet>(); var tntable = tnbrs.AsQueryble();<code> var custdata = from c in db.CUSTs join t in tntable on c.NPA + c.NXX + c.LINE_NBR equals t

What's the implementation of List?

左心房为你撑大大i 提交于 2019-12-01 20:55:15
问题 I read this code: List<long> userIdList = new List<long>(); But I jumped to the definition(use VS2012) of List (in System.Collections.Generic ), I found: public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable { // Summary: // Initializes a new instance of the System.Collections.Generic.List<T> class // that is empty and has the default initial capacity. [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] public List

Merge and Update Two Lists in C#

元气小坏坏 提交于 2019-12-01 17:34:55
I have two List<T> objects: For example: List 1: ID, Value where Id is populated and value is blank and it contains say IDs from 1 to 10. 1,"" 2,"" ... 10,"" List 2: ID, Value and other attributes all filled with values but this list is a subset of List 1 in terms of IDs. (e.g only 3 items) 2,67 4,90 5,98 What I want is a merged list 1, but with updated values. Does anyone have any good extension method which will do this or any elegent code to perform this operation. The final list should be: ID, Value 1,"" 2,67 //value from list 2 3,"" 4,90 5,98 6,"" ... 10,"" I would probably use a

sorting a generic list of doubles

雨燕双飞 提交于 2019-12-01 06:01:53
I have a generic list of doubles that show on the page like this: 1199.17 1199.17 1161.67 1161.67 1161.67 1161.67 1161.67 1161.67 1161.67 1161.67 1161.67 1161.67 1161.67 1161.67 1161.67 1199.17 1349.17 1349.17 1349.17 1349.17 1349.17 1349.17 1311.67 1311.67 1311.67 1311.67 1311.67 1349.17 2174.17 2174.17 2174.17 2174.17 2136.67 2136.67 2136.67 2136.67 2174.17 2361.67 2361.67 2361.67 2361.67 2361.67 2361.67 2361.67 2361.67 2399.17 2849.17 2849.17 2849.17 2849.17 2849.17 2849.17 2849.17 2849.17 3111.67 3111.67 3111.67 3149.17 I am trying to order them so that the lowest double is first. I tried