Answers for "c# const"

C#
6

constants in c#

class Calendar1
{
    public const int Months = 12;
}
Posted by: Guest on January-17-2021
2

const float c#

const int X = 0;
public const double GravitationalConstant = 6.673e-11;
private const string ProductName = "Visual C#";
Posted by: Guest on December-23-2019
0

csharp declare constan

public const int NUMBER = 9;
Posted by: Guest on December-29-2020
0

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.
*/
Posted by: Guest on September-12-2021

C# Answers by Framework

Browse Popular Code Answers by Language