C # Programming Fundamentals-Constants

Source: Internet
Author: User

C # Programming Fundamentals-Constants

Constants are immutable values that are known at compile time and do not change during the lifetime of the program. Constants are declared using the const modifier.

Constants must be initialized at declaration time, and the type of the constant must be one of the following types: sbyte/byte/short/ushort/int/uint/long/ulong/char/float/double/decimal/bool/string/ Enumeration type/reference type.

When the compiler encounters a constant modifier in C # source code, the literal value is replaced directly in the intermediate language code it generates. Because there is no variable address associated with a constant at run time, the Const field cannot be passed by reference and cannot appear as the left-hand value in the expression.

Constants can be marked as public/private/protected/internal or protected internal. These access modifiers define how the user accesses constants.

Constants can be accessed as static fields, but constants are not declared with the static keyword.

C # Programming Fundamentals-Constants

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.