C# initialized object values

c#, initialization, object

Solution

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 

Problem

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 :)

Original source

Related problems