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 between read only and constant
variables?

Answer Posted / dilip tiwari

For Eg I have used constant(public const int X = 123;
)in my assembly and compiled that assembly. After compiling
I haved used the .dll in myapplication then the value of X
is 123.After some time recognised that value of X is 234
then to make the changes I have to again recompile my
assembly and main application. But If I use redonly then I
have to just compile my assembly and the reference of new
dll in my main application. No need to recompile my main
application

using System;
public class A
{
public const int X = 123;
}

csc /t:library /out:A.dll A.cs

using System;
public class MyTest
{
public static void Main()
{
Console.WriteLine("X value = {0}", A.X);
}
}

csc /r:A.dll MyTest.cs

To run: mytest
The output :
X value = 123

Then you install the program into your client computer. It
runs perfectly.
One week later, you realised that the value of X should
have been 812 instead of 123.
What you will need to do is to

1] Compile A (after making the changes)
csc /t:library /out:A.dll A.cs

2] Compile your application again
csc /r:A.dll MyTest.cs

This can be a little troublesome. However, if you used the
readonly instead of const,the situation will be slightly
different. You start with

using System;
public class A
{
public static readonly int X = 123;
}

csc /t:library /out:A.dll A.cs

using System;
public class MyTest
{
public static void Main()
{
Console.WriteLine("X value = {0}", A.X);
}
}

csc /r:A.dll MyTest.cs


To run: mytest
The output :
X value = 123

Now you realised, you have made a mistake. All you need to
do is

1] Recompile A.cs (after making changes)
csc /t:library /out:A.dll A.cs

2] Copy the new dll to the client computer and it should
run perfectly. There is no need to recompile your
application MyTest.cs here

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a syntax for writing a event delegate.

938


What is difference between .net and c#?

931


When should we use delegates in c#?

922


Can I use ReaderWriterLock instead of Monitor.Enter/Exit for Threading?

972


what is boxing and unboxing?can we initialize unboxing directly?

883


In which order the destructor is called for an inherited class?

979


How does inheritance work in c#?

1111


What is parameter c#?

1027


Can enum be null c#?

1002


Can the nested class access, the containing class. Give an example?

873


What is the difference between var and dynamic types in c# 4.0?

1014


What are data types examples?

934


Explain the difference between user control and custom control. Also, explain their use.

1055


What is the difference between struct and class in c#?

1248


What's the difference between the debug class and trace class? Documentation looks the same.

1081