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...

Difference between ByVal and ByRef?

Answer Posted / bharat

Hi All,By theoretical definition, it's true if we pass
parameter as value type we are passing a copy of value not
original copy.So changes are not reflect on original
value,now there is a catch what if i pass "Reef
type"(Classes,Delegates,Interface etc) as value type

e.g.
//------------------By Val
tryFunction TF1 = new tryFunction();
TF1.Age = 20;
TestFunction(TF1);
Response.Write(TF1.Age.ToString());
void TestFunction1(ref tryFunction tf)
{
tf.Age = 35;
}

public class tryFunction
{
private int age;
public int Age
{
set
{
age=value;
}
get{return age;}
}

-----------------------------------
Then what should be the return value.
According to concept it is 20,but on reality it is 35.So
where I am wrong?

Is This Answer Correct ?    0 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is an int in c#?

867


Is inheritance possible in c sharp?

1009


Can private virtual methods be overridden in c#.net?

863


Can I do things in il that I can't do in c#?

884


Why do we need abstract class?

853


what is the index value of the first element in an array?

895


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

843


What is the syntax for calling an overloaded constructor within a constructor?

918


How to implement delegates in c#.net

969


What's the implicit name of the parameter that gets passed into the set method/property of a class?

954


What is class method?

895


Why do we use threads in c#?

953


What is a console operator?

857


Are there constructors in c sharp?

916


What is instantiating a class?

885