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 |
If a class is a ref type, how we can pass to a function.
What does async mean in c#?
How do I create a multi language, multi file assembly?
What is difference between variable and property in c#?
What are constructors in c#?
What is lazy keyword in c#?
What are the delegates in c#?
Distinguish between continue and break statement?
What is difference between ilist and list?
What is Fragmentation and its Types?
Can u create multiple threads of execution ?
1 Answers IBM, ITC Infotech, UHU,
Give an example to show for hiding base class methods?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)