C # .NET: Const vs. readonly

xiaoxiao2021-03-06  48

Summarize the difference between Const and Readonly: The value of const and readonly can no longer be rewritten once initialization;

ConST can only initialize the declaration; readonly can initialize both in the declaration or in the constructor; constiTi is implies Static, and you can write Static const; readonly, you don't default static, if you need to write static readonly; consteration Component static resolution constant (so its expression must be evaluated when compiling); readonly is a constant of running period dynamically parsing; consts can be used to modify members in the class, or modify partial variables within the function; Readonly can only be used for members in the modified class

转载请注明原文地址:https://www.9cbs.com/read-40844.html

New Post(0)