I’m used to the syntax below when returning simple objects. It’s easier, shorter, cleaner and neater.
return Stuff{ Prop1 = "a", Prop2 = 5 };
However, for some reason, I can’t instantiate ClientCredentials the same way. I want to specify UserName property but intellisense just gives me a huge list of confusing stuff that I’m not sure what to do with. And the property I’m looking for isn’t there. I thought that syntax was recommended and standard… What gives?
EDIT:
I’d like to use the syntax:
return ClientCredentials
{
UserName.Password = "abc123",
UserName.UserName = "server\\user"
};
instead of:
ClientCredentials clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = "server\\user";
clientCredentials.UserName.Password = "abc123";
return clientCredentials;
See MSDN article here here
It says that UserName property is a class with only a get accessor. There is also an example how to set its’ values – you cant do this with initialzer
EDIT: after OP comment:
you can’t set property’s properties in initializer, you’ll have to do it the old way