Basic Operation optimization of C # basics Handy Notes

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.