Permanent field member in C #

Hi everyone, I’m confused const long size =((long)int.Maxvalue+1)/4how I will mix it up ... and what will happen when we determine static const long size =((long)int.Maxvalue+1)/4... what is the readonlyparticipant ....

+3
source share
4 answers

Const

The constant member is determined at compile time and cannot be changed at run time. Constants are declared as a field using the const keyword and must be initialized as they are declared. For instance:

public class MyClass
{
  public const double PI = 3.14159;
}

cannot declare a class member as "static const".

  • Because member variables declared as "const" are already "static".

PI cannot be modified in the application anywhere else in the code, as this will cause a compiler error.

only for reading

, . , readonly , . :

public class MyClass
{
  public readonly double PI;

  public MyClass()
  {
    PI = 3.14159;
  }
}
+8

. . , . - ?

0

static const, a const static. ( "" XYZ " " ).

readonly , , .

readonly const , readonly , a const .

0

, , int (2 ^ 31).

const . ( - , , , ). , ( , ). , complier, .

0
source

Source: https://habr.com/ru/post/1761863/


All Articles