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
  • 13,146
  • 50
  • 126
  • 195

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
  • 35,875
  • 47
  • 158
  • 240
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,566
  • 3
  • 26
  • 34