constants in c#
class Calendar1
{
public const int Months = 12;
}
constants in c#
class Calendar1
{
public const int Months = 12;
}
const float c#
const int X = 0;
public const double GravitationalConstant = 6.673e-11;
private const string ProductName = "Visual C#";
csharp declare constan
public const int NUMBER = 9;
c# const
//c# doesn't have final however it has equivalent sealed, readonly, const
/**************************************************************/
//sealing a class
sealed class SealedClassA{
public void testA(){Console.WriteLine("test A");}
}
//class childclass : SealedClassDemo { } -> will lead to an error
//A class which is marked by keyword sealed cannot be inherited.
/**************************************************************/
//sealing a method
class SealedClassA{
public void testA(){Console.WriteLine("test A");}
}
class childclassB : SealedClassDemo {
public sealed override void testA(){Console.Write("test A B");}
}
//only methods with override can be sealed.
/**************************************************************/
//making a const
public const float x = 1.0f
// the value x can't be modified.
/**************************************************************/
//making a readonly
public static readonly uint l1 = (uint) DateTime.Now.Ticks;
/*The readonly keyword is different from the const keyword.
A const field can only be initialized at the declaration of the field.
A readonly field can be initialized either at the declaration or in a constructor.
Therefore, readonly fields can have different values depending on the constructor used.
*/
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us