Is there a way to change C# object values all at once...in one line?
So if I have a class Result
with string msg
and bool isPositive
and I already call the constructor somewhere before like var result = new Result();
can I change values somehow by not entering:
result.msg = "xxxxxx";
result.bool = false;
But doing something like what you can do while instantiating:
result { msg = "", bool = true}
I know I can do it by instantiating again a new object by:
var result = new Result() { msg = "", bool = true}
but that is not my question :)
Why don't you create a method that do that for you...
public void SetResult(string msg, bool flag)
{
myFlag = flag;
myMsg = msg;
}
and then you invoke it:
myResult.SetResult("xxx", false); // one line
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With