Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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 15-Nov-12 0:14am
arkiboys2.6K

1 solution

Rate this: bad
good
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 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).
  Permalink  
v2
Comments
arkiboys at 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)

  Print Answers RSS
0 OriginalGriff 420
1 CHill60 410
2 Sergey Alexandrovich Kryukov 384
3 PIEBALDconsult 245
4 BillWoodruff 243


Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2014
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