Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


What is the difference b/w constant & read only variable?

Answers were Sorted based on User's Feedback



What is the difference b/w constant & read only variable?..

Answer / test

Constant: The value of a constant variable is set at
compile time and can't be reset again.

Readonly: Can be set in a constructor or can be reset again.

Is This Answer Correct ?    19 Yes 1 No

What is the difference b/w constant & read only variable?..

Answer / sumesh

For Both Constants and Read only values, we can set values
for them only once.

In the case of Constants, we set the value at the compile
time itself. After that we cannot change it

Example:

class Test
{
const double pi = 3.14;
.......................
.......................

}

In the case of Read only data, we can set the value in the
constructor.

Example:

class Test
{
private double _bonus;

public Test(double bonus)
{
_bonus = bonus;
}

public double Bonus
{
get { return _bonus; }
}

}

Test a(5.25);
Test b(6.75);

In this case, at the time object creation, we can set the
value for the bonus. That is, we can decide the value at
the runtime. So a reaonly variable is also known as runtime
constants.


So, the basic difference is, in the case of contstant, the
value will be same across the objects of that class, but it
may differ in the case of readonly variables.

Is This Answer Correct ?    16 Yes 0 No

What is the difference b/w constant & read only variable?..

Answer / dharmendra

constant value set on initialization it not may be change or
reset when that readonly can be change in running time.

Is This Answer Correct ?    12 Yes 0 No

What is the difference b/w constant & read only variable?..

Answer / maloy.adhikari

Constants: The value can't be changed

Read-only: The value will be initialized only once from the
constructor of the class.


Const:
1)Can not be static.
2)The value is evaluated at compile time.
3)It is initialized at declaration only.
4)the const keyword is used for compile-time constants

Readonly:
1)Can be either instance-level or static.
2)The value is evaluated at run time.
3)It can be initialized in declaration or by code in the
constructor. Therefore, readonly fields can have different
values depending on the constructor used.
4)the readonly keyword is used for runtime constants.

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Dot Net Framework Interview Questions

what is .edmx file and what it contains?

0 Answers   Microsoft,


What is Reference type and value type

1 Answers  


what is VSS? Where we are using?

3 Answers   TCS,


What is serialization ?

7 Answers   IBM, Karrox, MMTS,


Explain .Net Framework? Why we use it?

0 Answers   MaxSolPro,


what is lazy loading in entity framework?

0 Answers   Microsoft,


Requirement is: try { \\SQL Query } catch(Exception i) { print a } catch(SQLQueryException e) { \\SQL Query } Qu)I Got Exception in "try" block. Which "catch" statement (i.e. 1st catch or 2nd catch ) catches the exception and Why???

6 Answers   3i Infotech,


When was .NET announced

1 Answers  


What is difference between shared and public

1 Answers  


What is main objective of asp.net mvc 4 or what is new in mvc4 ?

0 Answers  


What is oauth in web api?

0 Answers  


What is Peek method in Tempdata in ASP.Net MVC?

0 Answers  


Categories