|
-
December 18th, 2011, 10:55 PM
#1
what is the benifit of not creating instance of a static class in c#?
in normal class we need to create an instance of the class but in static class there is no need to create an instance of the class.
so my question is
what is the benifit of not creating instance of a static class over normal class in c#?
-
December 19th, 2011, 05:48 AM
#2
Re: what is the benifit of not creating instance of a static class in c#?
The main benefit is that you save on memory. For example to get the maths constant 'pi', which is 3.1415.... it'd be a terrible waste to have to create an entire class every time.
var x = Math.Pi;
versus
var constants = new MathsConstants ();
var x = constants.Pi;
The first case is a simple memory read of a constant value. The second case involves allocating memory, running a constructor and calling a property. This is considerably slower than the former if you want to do it a billion times a second.
www.monotorrent.com For all your .NET bittorrent needs
NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|