I was wondering what's the best practice for class initialization
.
One can write:
private myClass mc = new myClass();
Or:
private myClass mc { get; set; }
public Foo()
{
mc = new myClass();
}
I always tend to use it as a field
. Are there any downsides for using a class as a property
? I did some searching on google but none of the results gave me a good answer for this specific question.
If it's private, there's no significant benefit in making it a property. I'd just keep it as a field. I use properties as a way of communicating an API with other classes.
See more on this question at Stackoverflow