dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: what is the benifit of not creating instance of a static class in c#?

  1. #1
    Join Date
    Dec 2011
    Posts
    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#?

  2. #2
    Join Date
    May 2007
    Posts
    1,546

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)