Search results
23 lut 2016 · A const string can only be initialized using other constants or literals. Also, a static readonly string can be set in a static constructor; a const string can only be initialized inline. Note that a static string can be modified; you should use static readonly instead.
10 maj 2023 · You use the const keyword to declare a constant field or a local constant. Constant fields and locals aren't variables and may not be modified. Constants can be numbers, Boolean values, strings, or a null reference. Don’t create a constant to represent information that you expect to change at any time.
4 mar 2024 · Słowo kluczowe służy const do deklarowania pola stałej lub stałej lokalnej. Pola stałe i lokalne nie są zmiennymi i mogą nie być modyfikowane. Stałe mogą być liczbami, wartościami logicznymi, ciągami lub odwołaniem o wartości null.
12 mar 2024 · Constants are immutable values which are known at compile time and do not change for the life of the program. Constants are declared with the const modifier. Only the C# built-in types may be declared as const. Reference type constants other than String can only be initialized with a null value.
8 cze 2020 · Use the const keyword in C#. The const (read: constant) keyword in C# is used to define a constant variable, i.e., a variable whose value will not change during the lifetime of the program.
27 sty 2023 · In this article, we’ll see the different ways to hold constant or static values in C#. const: In C#, you can declare a const of any type as long as the value assigned can be fully evaluated at compile time. A constant member is defined at compile time and cannot be changed at runtime.
The const keyword is useful when you want a variable to always store the same value, so that others (or yourself) won't mess up your code. An example that is often referred to as a constant, is PI (3.14159...). Note: You cannot declare a constant variable without assigning the value.