8
Reply

What is the importance of using Const keyword in C#

Bala S

Bala S

6y
3.9k
2
Reply

    Const Value will NEVER gets changed.

    const is by default static and never change value throughout the application. We can access const entity via class name like ClassA.constVariableName

    Const keyword for making entity as constant, cannot modify the value later in the code.

    If we declare any variable to const type these variable value not change in life cycle of program

    when we define variable as const it means the variable valve can't be changed in whole application. you must have to assign the value of declaration time otherwise it will give compile error.

    The variable is fixed

    Const keyword will restrict developers from changing variable value

    Constants in C# provide a named location in memory to store a data value. It means that the value of the variable will be known in compile time and will be stored in a single place. When you declare it, it is kind of 'hardcoded' in the Microsoft Intermediate Language (MSIL).