Powered by Blogger.

Sunday, February 23, 2014

Constants in C#.Net

In this article we will check what are constants in C#.Net.

Also check out:

- Multithreading tutorial in C#.Net

- Bind gridview using datareader in asp.net

- How to handle exception in sql server stored procedure?

A constant is a variable whose value cannot be changed throughout its lifetime. We have to use const keyword to declare a constant like below:

const int number = 10;

some points to remember while working with constant:

- They must be initialized when they are declared; and after a value has been assigned, it can never be overwritten.

- The value of a constant must be computable at compile time. You can’t initialize a constant with a value taken from a variable. If you need to do this, you must use a read-only fi eld

- Constants are always implicitly static.