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?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is viewbag title?

942


i want to take the fast track training on >net Frame work and work flows and share point could you tellme the good institutes for that cources

2018


Explain ASP.NET MVC Identity and Security?

989


What are the new features 3.5 framework against with the tool?

1067


what is more complex to implement property, methods or event? how can I define criteria to compare the difficulty of implementation between them? for example the number of methods wanted to implements property is 2 methods. how many methods I need it to implements events?

2218


What is the version number for the next version of the .net framework, codenamed �orcas�?

943


What is stateless model?

952


What are the advantages of asp.net mvc?

1035


What is the .net framework and how does it work?

972


What is entity client data provider? : Entity framework

1058


How to change the action name in ASP.Net MVC?

1069


Why should we go for entity framework?

1009


What symbol would you use to denote, the start of a code block in razor views?

971


Which .net framework is installed?

969


How large is the .net framework 3.0? Does this change make the release larger?

1008