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 dataset c#?

496


Can you have an array of arrays?

508


What is a .exe extension files? How is it similar to .dll extension files?

582


What is array and its types in c#?

531


What does break do in loop?

493






What is .net console?

535


In a site to turn off cookies for one page which method is followed?

511


Is c# code is managed or unmanaged code?

493


What is the difference between abstract class and interface in c#?

499


What are collection classes?

488


Explain the types of comments in c#?

552


What are the basics of c#?

557


4. Describe the process when we send a request URL? And who is responsible for that?

1490


Describe the ways of cleaning up objects in c#.

524


What is action in c# 3.5?

546