Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Can you please let me know
1- when to use one over the other
2- Advantages/disadvantages of one over the other
3- When does the static class get created? when the class is called or when the program is compiled?

Thanks
Posted

1 solution

In static ,their exists only one object.So same object will share in program. Whenever you modify it then will effect to all.
In instance type, value will be unique.it will not share to all. When you change one object value will not effect to other.

When a class is static ,you can call member variable and function directly with out create object. But in other case need to create an object, this way provide security.

Static Classes are used when there is no reason to have instances like in .net Framework Math Class.

Math class is netural to be static becuase there is no good reason to have a object of this class and then maintain the object.


Please refer: Static Classes and Static Class Members (C# Programming Guide).
 
Share this answer
 
v2
Comments
arkiboys 16-Nov-12 12:48pm    
In my winform application, there is one generic method which gets called from every form by every user each time a user uses the application. Is it is a good idea that this method to be static in a static class?
I ask because, if it is not static, then the create instance has to be in so many places. I think it is just easier and better ? to have it as static?

What do you think please?
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900