2

Possible Duplicate:
When to Use Static Classes in C#

Questions in the title..........i would greatly appreciate opinions on when it's best to use each?

Regards

Community
  • 1
  • 1
Goober
  • 12,904
  • 50
  • 122
  • 192

2 Answers2

1

I use static classes when they just contain fairly simple helper methods. In other cases I use instances of objects, so that I can do dependency injection and write proper unit tests.

Grzenio
  • 34,674
  • 45
  • 154
  • 233
0

That's the case when you don't have access to that different class (see Jon Skeet's answer). However, when you do have access to the code then the rule I use is the following:

Can I get away with using a static class, or do I need to store different data in that class each time?

Hope this helps.

EDIT: Disregard the first sentence since Jon Skeet deleted his answer.

Community
  • 1
  • 1
tzup
  • 3,516
  • 3
  • 24
  • 33