Its said that property should not be “Set” only (Code analysis rule CA1044 )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?
I’d agree with that it’s a bit confusing with write only properties (from a client of the class points of view), so I try to avoid them and instead create a set method of some kind.
The way recommended by Microsoft also seems to be to rewrite it to a method (or make it read and write if suitable): http://msdn.microsoft.com/en-us/library/ms182165.aspx