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

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

WBOY
Release: 2023-09-03 13:17:02
forward
1568 people have browsed it

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
Copy after login

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

3.14159
235468E-7F
Copy after login

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"
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template