I have been using an API to do some work. This is how I used it first time round:
var someStuff = new myObject ();
someStuff.Name = "stackOverflow";
someStuff.Options.MaxSurname = 5; //this caused me to get a runtime exception, Options is Null
Fix was simple. I obviously had to new the Options member to create an instance.
someStuff.Options = new Options ();
someStuff.Options.MaxSurname = 5;
This now works as expected, obviously. Is this okay? As a client I was unaware that I had to new this Options member. Quick fix once I went to debug and got a runtime null object exception.
Yes this okay.
For some reason the API you’re using requires you to contruct an Options object, and the compiler cannot check for this (hence the exception at runtime).
You could also contruct the object before applying it to SomeStuff, if this feels more natural to you: