Differences between a non-generic set and a generic set

Source: Internet
Author: User

Differences between a non-generic set and a generic set
ArrayList array = new ArrayList (); array. add ("123"); array. add ("test"); array. add (300); Console. writeLine (array [2]); View Code

Adding such a non-generic set object will go through a packing process without knowing the type of the added object.

When Console. WriteLine (array [2]) is output, the box is split.

Therefore, in terms of performance, we can avoid such a situation.

List <int> list = new List <int> (); list. Add (1); list. Add (2); View Code

The type of such a generic set object is defined as int. in JIT, you no longer need to binning or unboxing.

 

Another difference between generics and non-generics is that for type constraints, generics are defined based on type security.

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.