Static Class in C#


Defination

The class which contain only static member and we canot create the instances of that class is called static class.

Features

  • They only contain static members.
  • They cannot be instantiated.
  • They are sealed.
  • They cannot contain Instance Constructors

When to Use ?

when we have to separate data and behavior that will be independent of any object identity. The data and functions do not change regardless of what happens to the object.

For Example Connection String of web confi file,mathematics function, or a currency converter class etc.

Advantages

  • Compiler makes sure that no instance of static class is created and no instance members are declared within a static class.  In previous version of C#, the constructor has to be marked private  to   avoid this from happening.
  • Static class also makes the implementation simpler and faster since we do not have to make instance of the class to call its method.

For more information refer this link

http://msdn.microsoft.com/en-us/library/79b3xss3%28VS.80%29.aspx

Advertisements

8 Responses to “Static Class in C#”

  1. hs87.beverungen-net.de Says:

    I absolutely love your website.. Great colors & theme. Did you create this web site yourself?
    Please reply back as I’m trying to create my own personal blog and want to find out where you got this from or just what the theme is called. Thank you!

    • Chandra Dev Says:

      Hi

      Thanks. Its is free theme from wordpress.

  2. self storage new york city Says:

    I believe everything posted was very logical. However, consider this, what if
    you added a little content? I am not saying your information isn’t solid., but suppose you added something that makes people want more? I mean Static Class in C# | Chandradev’s Blog is a little vanilla.

    You might peek at Yahoo’s home page and watch how they create article titles to get viewers to open the links. You might add a video or a related pic or two to grab readers interested about what you’ve got to say.
    Just my opinion, it would make your posts a little bit more interesting.

    • Chandra Dev Says:

      Hi

      Thanks for giving good suggestion. I will implement this tips in new articals.

  3. twilightgray.com Says:

    My brother recommended I would possibly like
    this website. He was totally right. This publish truly made my day.
    You can not consider simply how much time I had spent for
    this info! Thanks!

    • Chandra Dev Says:

      Thank you and glad to know that you liked my blog.

  4. click here Says:

    Hello my loved one! I wish to say that this post is awesome, great written and come with
    approximately all important infos. I would like to look
    extra posts like this .

    • Chandra Dev Says:

      Thanks for your kind word. I will keep on writing nice posts like this.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: