Click here to Skip to main content
13,145,774 members (58,843 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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?

Posted 15-Nov-12 0:14am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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 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).
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?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100