The basic operation of data query, deletion and so on is the basis of any programming language, so we study the common type of data operation in C #, and make a handy note.
When a list is queried, the Hashset<t> class is used when dealing with larger data, because the list is based on a linear table. But it has a two-point lookup (BinarySearch), so it can be sorted after the storage is complete. This is followed by a binary search. But you can also design:dictionary<tkey,list<t>> to use Dictionary's efficient search query capabilities for searching List<t> objects. But the data is using list< t> storage.
Hashset<t> is a collection class that does not contain duplicate types. This collection is based on hash values, and its operations are fast. Compared to Hashtable<tkey,tvalue> This collection class contains only one type parameter, Search elements are not stored based on key-value pairs. If you need to determine whether an element exists, you only need to call the contains () method.
List lookup complexity O (n), HashSet find complexity O (1)
Delete Add operation for dictionary class:
By default, the position of the element that is added is the position at which the element is deleted.
In the case of sorting, the position of the element added will still be the position of the element before it is unsorted.
Static voidMain (string[] args) {Dictionary<int,int> _dic =Newdictionary<int,int>(); _dic. ADD (3,3); _dic. ADD (1,1); _dic. ADD (2,2); _dic. ADD (6,6); Console.WriteLine ("unsorted:"); foreach(varKinch_dic) {Console.WriteLine (K.key+" "+k.value); } varDic_sort = fromDicinch_dic byDic. Me?Selectdic; Console.WriteLine ("non-processed:"); foreach(varKinchDic_sort) {Console.WriteLine (K.key+" "+k.value); } Console.WriteLine ("added processing after removal:"); _dic. Remove (2); _dic. ADD (4,4); foreach(varKinch_dic) {Console.WriteLine (K.key+" "+k.value); } console.read (); }
You can also test it yourself ...
Basic Operation optimization of C # basics Handy Notes