The advantage of using a static class is that the compiler can check to make sure that no instance members are accidentally added. The compiler will guarantee that instances of this class cannot be created. Static classes are sealed and therefore cannot
be inherited. Static classes cannot contain a constructor, although it is still possible to declare a static constructor to assign initial values or set up some static state.
Static Method
A non-static class can contain static methods, fields, properties, or events. The static member is callable on a class even when no instance of the class has been created.
The static member is always accessed by the class name, not the instance name. Only one copy of a static member exists, regardless of how many instances of the class are created.
Static methods and properties cannot access non-static fields and events in their containing type, and they cannot access an instance variable of any object unless it is explicitly passed in a method parameter.
Two common uses of static fields are to keep a count of the number of objects that have been instantiated, or to store a value that must be shared among all instances. Static methods can be overloaded but not overridden, because they belong to the class,
and not to any instance of the class. Although a field cannot be declared as static const, a const field is essentially static in its behavior. It belongs to the type, not to instances of the type.
.Net Professional & Cosultant
Blog: Dot Net TricksWindows Apps Please "Mark As Answer" if my suggestions helps you
gurunguns
Member
72 Points
209 Posts
Difference between Static method & Static class with static method?
Jan 19, 2013 04:40 AM|LINK
I am going to make manager for my controllers. But stuck with architectural appoach.
what is difference between Static method & Static class with static method?
which one to be used?
Save Green.
Real4ever
Member
48 Points
9 Posts
Re: Difference between Static method & Static class with static method?
Jan 19, 2013 02:32 PM|LINK
It depends on your needs, kindly provide some details about your logic so we can find the most efficient way.
very detailed description with example could be found here http://msdn.microsoft.com/en-us/library/79b3xss3(v=vs.80).aspx
ramramesh
Member
458 Points
158 Posts
Re: Difference between Static method & Static class with static method?
Jan 19, 2013 02:44 PM|LINK
Hai
Check
http://forums.asp.net/t/1355455.aspx/1
pro.shailend...
Participant
1000 Points
189 Posts
Re: Difference between Static method & Static class with static method?
Jan 19, 2013 02:52 PM|LINK
The main features of a static class are:
They only contain static members.
They cannot be instantiated.
They are sealed.
They cannot contain Instance Constructors
The advantage of using a static class is that the compiler can check to make sure that no instance members are accidentally added. The compiler will guarantee that instances of this class cannot be created. Static classes are sealed and therefore cannot be inherited. Static classes cannot contain a constructor, although it is still possible to declare a static constructor to assign initial values or set up some static state.
Static Method
A non-static class can contain static methods, fields, properties, or events. The static member is callable on a class even when no instance of the class has been created.
The static member is always accessed by the class name, not the instance name. Only one copy of a static member exists, regardless of how many instances of the class are created.
Static methods and properties cannot access non-static fields and events in their containing type, and they cannot access an instance variable of any object unless it is explicitly passed in a method parameter.
Two common uses of static fields are to keep a count of the number of objects that have been instantiated, or to store a value that must be shared among all instances. Static methods can be overloaded but not overridden, because they belong to the class, and not to any instance of the class. Although a field cannot be declared as static const, a const field is essentially static in its behavior. It belongs to the type, not to instances of the type.
Blog: Dot Net Tricks Windows Apps
Please "Mark As Answer" if my suggestions helps you