I use the following snippet of pseudocode to clarify my question (the class used does not matter):
var client = new SmtpClient(); client.Credentials = ...;
Now, if I want to use this code. How do I know how to use it. I could try setting the property value as follows:
client.Credentials.User = "MyUsername";
which should give me a NullReferenceException because the default credential object is not set. Or I could use it like this:
client.Credentials = new Credentials("MyUsername",...);
But the correct way to initialize a property would be to set the value of DefaultNetworkCredentials as follows:
client.Credentials = CredentialCache.DefaultNetworkCredentials;
How do I know if an object property has a default value during development without looking at the documentation (if one exists)?
What is the best practice / design for object properties? Should there always be a default value for a property?
source share