what is the main differnce between const,readonly and static
Answers were Sorted based on User's Feedback
Answer / komilla shaheen
const is the keyword where we can intialize the variable
with some value which is constant throughout the program it
cannot be changed.
static is the keyword which is intialized at complile time
and had to change at compile time only.
readonly is for the varible which is readonly cant be
changed.
Is This Answer Correct ? | 9 Yes | 1 No |
Answer / vijay rana
const is used to create a constant value which will be
constant throuout the class
static is used for a commaon variable for all objects, it is
not part of a object, it is a part of class, every object
will share this value,
read,
there are many situation in which we want to intialize the
value of a constat variabl at run time, in which we can have
different values for different objects, with the help of
readonly we can define the value of any object at runtime
which will not be changed later
Is This Answer Correct ? | 6 Yes | 0 No |
Answer / raja
1. we can initialize constant variable only at the
declaration where as readonly varaiable can be initialized
at either declaration or in constructor.
2. we can't use static modifier for the const variable
where as readonly variable can be declared as static
Is This Answer Correct ? | 5 Yes | 0 No |
How to move to a state-related codebase?
What is the difference between “dispose” and “finalize” variables in c#?
What is Interface? Explain with an example.
What is ildasm.exe used for?
What does the term immutable mean?
3 Answers Satyam, Siebel Systems, Techno Labs,
What is int32?
In the page load event I assigned dropdownlist’s datasource property to a valid list. On the submit button click.. The same datasource property is coming as null. Why?
What?s the difference between an interface and abstract class?
Can arraylist hold primitive types?
Is it possible to restrict the scope of a field/method of a class to the classes in the same namespace?
Why do we need indexer in c#?
What is the use of console application in c#?