How to set a value from another class
Posted
by Ram
on Stack Overflow
See other posts from Stack Overflow
or by Ram
Published on 2010-05-12T08:02:41Z
Indexed on
2010/05/12
8:14 UTC
Read the original article
Hit count: 146
Its said that property should not be "Set" only and it should be "Get" as well. What should i do if I need to set value to a variable from some other class?
The will keep changing so I cannot pass it through constructor.
Shall I create a function for this as shown below?
class A
{
public void SetValue()
{
b = new B();
b.SetTest(10);
}
}
class B
{
int test;
public void SetTest(int value)
{
test = value;
}
}
What are the other alternatives?
© Stack Overflow or respective owner