private MinhaClasse minhaclasse;
minhaclasse = new MinhaClasse();
I put in the Github for future reference.
This code makes no sense, if it is inside a method the first line does not compile, if it is outside a method the second line does not compile.
I imagine you’re talking about a static method, because if it’s an instance, the first option is your only option.
For a static method does not matter, both work the same.
However, it is considered a little confusing to call a static method as if it were an instance, so the second option would be the most suitable to give more readability and prevent any error from happening by trying to access a null instance in something that should always work. So it’s not recommended.
Imagine you call a method by the instance that does something that you assume will happen with the instance, but because it is a static method it occurs globally. It’ll take a while to figure out why you don’t do what you expect.
C# chose not to allow the first option to avoid confusion.
If your concern is whether you should create the method as static or not, I’m one of those who thinks you should always create a static method until it needs to be instance, and often is. The most common is that members of a class need to be bound to the instance.
And my choice for the method is not even performance, which is even faster, is to avoid exposing something that is not necessary. If you do not depend on anything that is in the instance why do that method be instance? Of course you need to ask yourself why it has no relation to the instance. It may have been a wrong decision.
Related When we should declare a method as static?
– ramaral