1

I have searched a lot difference between singleton and static class, Only I could convince myself is syntactical difference,on which I am not interested.

Could anyone tell me the real difference between static and singleton ? When I should use only singleton not static or any other ?

keerti_h
  • 383
  • 2
  • 13
  • 3
    You can see [this thread](http://stackoverflow.com/questions/519520/difference-between-static-class-and-singleton-pattern) – ali Apr 28 '16 at 06:54

1 Answers1

0

In short, Singleton has a (single) instance, while static class has none. So when you want to pass the instance, choose Singleton, e.g.:

  // EventArgs.Empty is a Singleton
  DoOnChange(myObject, EventArgs.Empty);

when you have no need in any instances use static class:

  public static class MyMath {
    public static Double GammaFunc(Double value) {...}
    ...
  }
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
  • But I can have a function in static class which serves the purpose of the object being passed. i.e if any outer class changes the value inside the function, will be impacted everywhere @ Dmitry Bychenko – keerti_h Apr 28 '16 at 07:00
  • 1
    @keerti_h: that's so called *side effect* which we usually should avoid for the reason you've named: "will be impacted everywhere" (or at least "elsewhere") – Dmitry Bychenko Apr 28 '16 at 07:03