C # Use readonly or const?

Source: Internet
Author: User
Readonly is the runtime time, and const is the Compilation Time. The former is flexible and the latter is efficient. The former can be used for any type, and the latter can only be used for numbers and strings;
From the above comparison, the only advantage of const over readonly is its efficiency. But how much can it be higher? We use advanced languages like C # To write applications. Program, Far from using countless constant values (such as message IDs) like writing an operating system in C, in the use of a few constants, the performance advantage of using const is minimal. Therefore, we use readonly instead of Const.

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.