Home  >  Article  >  Backend Development  >  What is the difference between literals and constants in C#?

What is the difference between literals and constants in C#?

WBOY
WBOYforward
2023-09-03 13:17:021467browse

C# 中的文字和常量有什么区别?

Constant refers to a fixed value that cannot be changed during the execution of the program. These fixed values ​​are also called literals. Constants can be of any basic data type, such as integer constants, floating-point constants, character constants, or string literals. There are also enumeration constants.

Integer literals can be decimal or hexadecimal constants. The prefix specifies the base: 0x or 0X for hexadecimal, no prefix for decimal.

150
300u

Floating point numerical quantities include integer part, decimal point, decimal part and exponent part.

3.14159
235468E-7F

String literals or constants are enclosed in double quotes "" or @"". Strings contain characters similar to character literals: ordinary characters, escape sequences, and universal characters.

@"Welcome User"
"Welcome User"

The above is the detailed content of What is the difference between literals and constants in C#?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete