In C #, compiled constants (const) and run-times (readonly)

Source: Internet
Author: User

The ReadOnly keyword differs from the const keyword. the const field can only be initialized in the declaration of the field.  

const field can only is initialized at the declaration of the field." >readonly field can be initialized either at the declaration or in a constructor." The readonly  field can be initialized in a declaration or constructor.  readonly fields can has different values depending on the constructor used. " > So, depending on the constructor used,

readonly field can be initialized either at the declaration or in a constructor." >readonly fields can has different values depending on the constructor used. " > the readonly  field may have different values .  const field is a Compile-time constant, the readonly field can be used for Run-time constants, as in the line: public static readonly UI NT L1 = (UINT) DateTime.Now.Ticks; " In addition,   const  field is a compile-time constant, readonly field can be initialized either at the declaration or in a constructor." >readonly fields can has different values depending on the constructor used. " >const field is a Compile-time constant, the readonly field can be u Sed for Run-time constants, as in the line: public static readonly uint L1 = (uint) DateTime. Now.ticks; " >READONLY 

readonly field can be initialized either at the declaration or in a constructor." >readonly fields can has different values depending on the constructor used. " >const field is a Compile-time constant, the readonly field can be u Sed for Run-time constants, as in the line: public static readonly uint L1 = (uint) DateTime. Now.ticks; " > word readonly field can be initialized either at the declaration or in a constructor." >readonly fields can has different values depending on the constructor used. " >const field is a Compile-time constant, the readonly field can be u Sed for Run-time constants, as in the line: public static readonly uint L1 = (uint) DateTime. Now.ticks; " >

readonly field can be initialized either at the declaration or in a constructor. " >readonly fields can has different values depending on the constructor used." >const field is a Compile-time constant, the readonly field can being used for run-t IME constants, as in the line: public static readonly uint L1 = (uint) DateTime.Now.Ticks; " > You should try to use run-time constants 。 The reason is that variability constants are slightly faster in performance. But there is no

readonly field can be initialized either at the declaration or in a constructor. " >readonly fields can has different values depending on the constructor used." >const field is a Compile-time constant, the readonly field can being used for run-t IME constants, as in the line: public static readonly uint L1 = (uint) DateTime.Now.Ticks; " > transport readonly field can be initialized either at the declaration or in a constructor. " >readonly fields can has different values depending on the constructor used." >const field is a Compile-time constant, the readonly field can being used for run-t IME constants, as in the line: public static readonly uint L1 = (uint) DateTime.Now.Ticks; " > is based on the constructor used.

readonly field can be initialized either at the declaration or in a constructor. " >readonly fields can has different values depending on the constructor used." >const field is a Compile-time constant, the readonly field can being used for run-t IME constants, as in the line: public static readonly uint L1 = (uint) DateTime.Now.Ticks; " >readonly field may have different values.

readonly field can be initialized either at the declaration or in a constructor. " >readonly fields can has different values depending on the constructor used." >const field is a Compile-time constant, the readonly field can being used for run-t IME constants, as in the line: public static readonly uint L1 = (uint) DateTime.Now.Ticks; " > The compiled constants can be declared in the method, while the read-only run-time constant cannot be declared in the method.

Changing the value of a public compile-time constant should be treated as a modification of the type interface and must recompile all

The code that references the constant. While changing the value of a read-only constant is only a modification to the type implementation, it only needs to be repaired.

You can change yourself.

In C #, compiled constants (const) and run-times (readonly)

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.