I have three classes (Data
, First
, Second
).
I'm creating member of Data
in First
and try to pass it to Second
with the following:
public class First
{
public Data DataMember;
Second SecondMember;
void First_Function()
{
SecondMember.Second_Function(ref DataMember);
}
}
public class Second
{
Data DataMember;
public void Second_Function(ref Data data)
{
}
}
Is there a way to access the First.Data
member in Second.Data
member?
Using ref
in the Second.Second_Function()
allows me to access the member of the First
but only inside the Second_Function()
.
I want another function in Second
to access it, that has a different "call back time" as the Second_Function()
.
Edit :
My question in not about what is the difference between the reference and value type .
if I use ref keyword for a int variable , that mean if I replace it with another value it will effect the original .
in class when I have two variable reference to the same instance if I edit one of them I effect the other , that's because they reference to the same thing ,I want to know if there is a way in C# to replace one of the variable ,and make the other variable change with it .