I am having a simple class with 3 not null integer members
public class Test
{
public int Test1 { get; set; }
public int Test2 { get; set; }
public int Test3 { get; set; }
}
Now I want to use something like this
int? var1 = null;
int var2 = 2;
int var3 =5;
var t = new Test
{
Test1 = var1, // (error) Initialize Test1 only when var1 is not null
Test2 = var2,
Test3 = var3
};
i.e. I just want to initialize member Test1 only if var1 is not null, so somehow I need to put a check while initialization. I know its a simple question and can be done in diifferent ways but as I am refactoring the existing code and generalizing it, I need solution through Object Initialization only. Looking simple to me but somehow could not able to find solution by myself
Not much experienced programmer, so really appreciate any help