praveen1981
asked on
all static methods can be used in normal class then why static class
Hi
here i can use all the static variables, static methods and static constructor in the normal class , then why the static
Class is Required what is the exact difference, as i know that static class will load in to the memory at the time of application loads, is that only difference, then when the static method in the normal class will loads in to the memory.
Please clarify.
here i can use all the static variables, static methods and static constructor in the normal class , then why the static
Class is Required what is the exact difference, as i know that static class will load in to the memory at the time of application loads, is that only difference, then when the static method in the normal class will loads in to the memory.
Please clarify.
static class does have constructor.
ASKER
Hi
But what ever we are achieving with static class we can achieve with static methods or static constructors or static variables from normal class, then why exactly i requrired the static class.
But what ever we are achieving with static class we can achieve with static methods or static constructors or static variables from normal class, then why exactly i requrired the static class.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you can achieve everything you were doing with the static class using a regular class then you didn't need the static class.
One non-technical difference would be convenience. With the static class you don't need to instantiate it and you can access everything from anywhere in the application. For the simplest of projects this is helpful as you don't have to pass a reference to the class around. There is valid use for static members...but it sounds like you don't need them for your current situation.
One non-technical difference would be convenience. With the static class you don't need to instantiate it and you can access everything from anywhere in the application. For the simplest of projects this is helpful as you don't have to pass a reference to the class around. There is valid use for static members...but it sounds like you don't need them for your current situation.
I agree with Idle Mind. Let me also add (and this is important in some cases) that static classes are not thread-safe out of the box.
ASKER
I was not completely satisfy with the answer
"I was not completely satisfy with the answer"
...then ask more follow-up questions next time until you are satisfied. =)
...then ask more follow-up questions next time until you are satisfied. =)
A static class is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated. In other words, you cannot use the new keyword to create a variable of the class type. Because there is no instance variable, you access the members of a static class by using the class name itself. For example, if you have a static class that is named UtilityClass that has a public method named MethodA, you call the method as shown in the following example:
Open in new window
2) When to use static class
Basically they are used when they just contain fairly simple helper methods
They're very easy to use, no instantiation, no disposal, just fire'n'forget.