The "Object reference not set to an instance of an object" is a pretty famous error and has a canonical answer here. The error is not in the line where you try to initialize the model variables but in later use of the variables model1, model2, model3 and model4 only the last one model5 is created and initialized.
If you were happy with a collection, then there wouldn't be much of a problem. You could create an array for 5 MyData instances and loop over that array to initialize the 5 instances with the same values, but if you want to have 5 separate instances each assigned to 5 different variables names in a single line then, as far as I know, the feature doesn't exist and perhaps there is no real reason to have it. But I don't know if future releases of the language will allow it.
In the meantime there is a possible workaround albeit not the most clear solution. (Still, do you really need it?) It involves the use of a Tuple of 5 MyData
You can implement a static method inside the MyData class that return the 5 initialized variables like here
public class MyData
{
public int Max { get; set; }
public int Min { get; set; }
public static (MyData model1, MyData model2, MyData model3,
MyData model4, MyData model5)
FiveInstanceFactory(int max, int min)
{
MyData[] factory = new MyData[5];
for (int x = 0; x < factory.Length; x++)
factory[x] = new MyData {Max = max,Min = min};
return (factory[0], factory[1], factory[2], factory[3], factory[4]);
}
}
Now you can have your one liner to create the 5 instances with the 5 names you like.
(MyData model1, MyData model2, MyData model3,
MyData model4, MyData model5) = MyData.FiveInstanceFactory(0,0);
model1.Max ++;
model2.Min++;
Console.WriteLine($"Min={model1.Min}, Max={model1.Max}");
Console.WriteLine($"Min={model2.Min}, Max={model2.Max}");