Meeting Creation Instructions

Is there a thumb rule about the number of static functions you can have in an assembly?

How do you know if a function should be a static v / s function that should not be static?

+5
source share
3 answers

Well, there is no rule of thumb - it comes down to the design argument. If you were listening to FxCop, the method would be fat to be static if it does not work on instances of the class class ...

I prefer to use the old definition, the method should be static if it is separated by type and not defined for the type instance.

This link contains the "When to Use" section:

http://msdn.microsoft.com/en-us/library/79b3xss3(VS.80).aspx

+3

, DI IoC, , , static , . "singleton", IoC, / .

, , . -, , GC, CLR, ( 32 ., ). , , , / .

, :

  • [ThreadStatic] static , , -
  • .NET, ConfigurationSection, ConfigurationElement ..
    • [ConfigurationProperty()], , , ,
  • ... , IoC .
+1

I thought the rule of thumb was to make it static, if possible. In other words, if a method needs to access the fields of an instance, then it cannot be static. Otherwise it should be.

+1
source

All Articles