I am creating a class in C# which eventually will be part of a library that other users can use. A user of this class has to set some properties and then use a public method to retrieve the results. What shall I do when a user calls the method without setting all the properties? Throw exception and expect the user to catch it?
Thanks
It might be better to create a constructor that takes the parameters, so that you are constructing an object instance that is in a usable state.
Along with all the other options that have been mentioned you could have the properties set to default values. Then the user has to set them to something different if they don't want the default behavior. But really without knowing more about what your code is doing it's hard to say what the best option is.
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