why we can use static method in c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • srinu sanaka
    New Member
    • Jan 2013
    • 1

    why we can use static method in c#

    what is static method?
    why we can use static method inc#?
  • zenzai
    New Member
    • Jan 2013
    • 1

    #2
    In short:

    "A static field is one whose value is shared by all instances of a class; its value conceptually belongs to the class as a whole instead of belonging to any one instance/object of that class....Just as static fields/properties are associated with a class as a whole versus relating to a specific individual object, static methods are in turn methods that can be invoked on a class as a whole. Static methods are useful for implementing general-purpose functionality— mathematical evaluations, for example—that can be used by any number of classes."

    Quote from "Beginning C# 2008 Objects - From Concept to Code", one of the best books (if not THE best) you can get about OOP in C#.

    Comment

    • Joseph Martell
      Recognized Expert New Member
      • Jan 2010
      • 198

      #3
      To add to zenzai's excellent response:

      A static method is one that belongs to a class, but not an instance of that class. In other words, it can be called without having to have to reference an instance of a class. There are too many reasons that this is important/useful to list here, but one of the best examples is the factory method programming pattern.

      Comment

      Working...