Hello Friends, In this tutorial we are going to discuss Static Vs Non Static Keyword in C#. Both Static and Non-Static have their own purpose. We are going to discuss them here.

After completing this tutorial we would be able to understand:

  • What is Static Class, Static Methods?
  • Static vs Non-Static in C#.

Static vs Non Static Keyword in C#:

The term static defines relating to itself. A Static Class is similar to itself with the difference is that we cannot create an instance of a static class. In another word, we cannot use new keyword with the static class to create an instance of the class. Since we cannot create an instance of a static Class, we can access the members of the static class using the class name directly.

If we declare a method or variable as static inside the class we can access the member of that class using the class name no need to create an object of that class.

A Static Variable can be used for those values which cannot be stored by instance. For example, if I need to keep count of how many instances of a class exist, we can use a static variable in such type of scenario.

Static Vs Non Static

There are following characteristics related to Static Class.

  • A Static Class can contain only static members.
  • We cannot create an instance of the Static class.
  • When you define a class as static you do not have access to the Non-Static field of that class. You can use only static members of that class.
  • A Static class cannot implement the interface.
  • You cannot add an abstract keyword to static class they are implicitly abstract.
  • There is no default constructor for the static class. Also, we cannot create a Constructor for Static Class.

Let’s create an example using Static and Non Static method in C#.

Open Visual Studio and Create a C# application.

Non-Static Method Example:

You can see in the above example we have created a Non-Static method called NonStaticCall. Since it is a Non-Static method we can call this method after creating an instance of the class that is what I did in the Main method. I have created an Instance of the Program Class and called the NonStaticCall method.

Static Method Example:

As in the above program, I have created a Static method called StaticCall. We don’t need to create an instance of the class for calling this static method. We can just call this method using Class Name as we did above.

View More:

Conclusion:

Hope you loved this post about Static Vs Non Static Keyword in C#. I would appreciate your Feedback, Comments and Suggest.

Thank You.

 

Explore post tags

96 Comments

  • Hello, i believe that i saw you visited my website thus i got here to go back the choose?.I’m attempting to find things to improve my site!I suppose its good enough to use a few of your ideas!!|

  • Link exchange is nothing else however it is simply placing the other person’s web site link on your page at appropriate place and other person will also do same in support of you.|

  • Howdy! This blog post couldn’t be written much better! Reading through this post reminds me of my previous roommate! He continually kept talking about this. I will send this information to him. Fairly certain he will have a very good read. Thanks for sharing!|

  • I’m pretty pleased to uncover this page. I want to to thank you for ones time for this particularly wonderful read!! I definitely enjoyed every little bit of it and I have you book-marked to see new things in your website.|

  • Great work! This is the type of info that are supposed to be shared across the net. Disgrace on Google for not positioning this publish upper! Come on over and talk over with my web site . Thanks =)|

  • I am curious to find out what blog system you are using? I’m having some minor security issues with my latest blog and I would like to find something more safe. Do you have any suggestions?|

  • Admiring the time and energy you put into your site and in depth information you present. It’s nice to come across a blog every once in a while that isn’t the same out of date rehashed information. Fantastic read! I’ve saved your site and I’m adding your RSS feeds to my Google account.|

  • I would like to thank you for the efforts you’ve put in penning this blog. I am hoping to view the same high-grade content from you later on as well. In truth, your creative writing abilities has encouraged me to get my own, personal blog now ;)|

  • Its like you read my mind! You appear to know so much about this, like you wrote the book in it or something. I think that you can do with a few pics to drive the message home a little bit, but other than that, this is magnificent blog. A fantastic read. I’ll definitely be back.|

  • Hi my family member! I want to say that this article is amazing, great written and include almost all important infos. I would like to see more posts like this .|

  • Fine way of describing, and fastidious piece of writing to get information about my presentation topic, which i am going to deliver in college.|

  • This is really interesting, You are a very skilled blogger. I’ve joined your feed and look forward to seeking more of your magnificent post. Also, I have shared your web site in my social networks!|

  • Hello! Someone in my Myspace group shared this website with us so I came to give it a look. I’m definitely enjoying the information. I’m bookmarking and will be tweeting this to my followers! Exceptional blog and outstanding style and design.|

  • Its not my first time to pay a visit this web page, i am browsing this web site dailly and obtain good facts from here everyday.|

  • Hi would you mind sharing which blog platform you’re working with? I’m planning to start my own blog soon but I’m having a difficult time deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I’m looking for something unique. P.S My apologies for getting off-topic but I had to ask!|

  • I every time emailed this web site post page to all my contacts, since if like to read it next my contacts will too.|

  • Good day very nice website!! Man .. Excellent .. Wonderful .. I’ll bookmark your website and take the feeds additionally? I’m satisfied to find a lot of helpful info here within the put up, we need develop extra techniques in this regard, thanks for sharing. . . . . .|

  • Asking questions are really pleasant thing if you are not understanding anything totally, but this paragraph provides fastidious understanding yet.|

  • Quality content is the main to be a focus for the visitors to go to see the web page, that’s what this web page is providing.|

  • Hey I am so delighted I found your blog page, I really found you by mistake, while I was researching on Askjeeve for something else, Anyhow I am here now and would just like to say thank you for a marvelous post and a all round interesting blog (I also love the theme/design), I don’t have time to look over it all at the moment but I have book-marked it and also added your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the fantastic work.|

  • Hurrah! After all I got a blog from where I know how to truly get valuable information concerning my study and knowledge.|

  • hello!,I like your writing very a lot! percentage we keep up a correspondence extra about your post on AOL? I need a specialist on this area to solve my problem. May be that is you! Taking a look ahead to look you. |

  • I loved as much as you’ll receive carried out right here. The sketch is tasteful, your authored subject matter stylish. nonetheless, you command get got an edginess over that you wish be delivering the following. unwell unquestionably come more formerly again as exactly the same nearly very often inside case you shield this increase.|

  • hey there and thank you for your info – I’ve definitely picked up something new from right here. I did however expertise several technical points using this site, as I experienced to reload the site many times previous to I could get it to load properly. I had been wondering if your web hosting is OK? Not that I’m complaining, but slow loading instances times will very frequently affect your placement in google and can damage your high quality score if ads and marketing with Adwords. Anyway I’m adding this RSS to my e-mail and could look out for a lot more of your respective fascinating content. Make sure you update this again very soon.|

  • fantastic post, very informative. I ponder why the opposite specialists of this sector do not understand this. You must proceed your writing. I’m sure, you have a huge readers’ base already!|

  • Wonderful blog! Do you have any suggestions for aspiring writers? I’m hoping to start my own blog soon but I’m a little lost on everything. Would you advise starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m completely confused .. Any recommendations? Many thanks!|

  • Its like you read my mind! You appear to know a lot about this, like you wrote the book in it or something. I think that you could do with a few pics to drive the message home a little bit, but other than that, this is wonderful blog. A great read. I’ll certainly be back.|

  • hello there and thank you for your information – I’ve definitely picked up something new from right here. I did however expertise some technical issues using this web site, as I experienced to reload the web site lots of times previous to I could get it to load properly. I had been wondering if your web hosting is OK? Not that I’m complaining, but slow loading instances times will often affect your placement in google and could damage your quality score if advertising and marketing with Adwords. Well I am adding this RSS to my email and could look out for a lot more of your respective exciting content. Ensure that you update this again soon.|

  • I’m no longer positive the place you are getting your info, but good topic. I needs to spend some time learning more or figuring out more. Thanks for magnificent info I was searching for this information for my mission.|

  • It’s truly very difficult in this active life to listen news on Television, thus I just use internet for that purpose, and get the hottest information.|

  • If some one wants expert view regarding blogging and site-building then i advise him/her to pay a visit this website, Keep up the pleasant work.|

  • I have seen that today, more and more people are being attracted to digital cameras and the issue of picture taking. However, being a photographer, you have to first invest so much period deciding which model of camera to buy in addition to moving store to store just so you might buy the most inexpensive camera of the brand you have decided to choose. But it isn’t going to end at this time there. You also have to take into consideration whether you should purchase a digital camera extended warranty. Thanks alot : ) for the good ideas I gained from your weblog.

  • Hi there! I know this is kinda off topic but I’d figured I’d ask. Would you be interested in trading links or maybe guest authoring a blog article or vice-versa? My website covers a lot of the same topics as yours and I feel we could greatly benefit from each other. If you might be interested feel free to shoot me an email. I look forward to hearing from you! Awesome blog by the way!|

  • Whoa! This blog looks just like my old one! It’s on a completely different subject but it has pretty much the same layout and design. Excellent choice of colors!|

  • When some one searches for his essential thing, thus he/she needs to be available that in detail, thus that thing is maintained over here.|

  • Hey there just wanted to give you a quick heads up. The words in your content seem to be running off the screen in Ie. I’m not sure if this is a format issue or something to do with browser compatibility but I figured I’d post to let you know. The layout look great though! Hope you get the problem resolved soon. Cheers|

  • Hello everyone, it’s my first pay a visit at this web site, and post is genuinely fruitful for me, keep up posting these types of articles or reviews.|

  • It’s a pity you don’t have a donate button! I’d without a doubt donate to this brilliant blog! I suppose for now i’ll settle for bookmarking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this site with my Facebook group. Talk soon!|

  • Hi, I think your blog might be having browser compatibility issues. When I look at your website in Ie, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, very good blog!|

  • Wow, marvelous blog layout! How long have you been running a blog for? you made running a blog look easy. The full glance of your website is wonderful, let alone the content material!

  • Hi! I could have sworn I’ve been to this site before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

  • Hello, Neat post. There’s an issue together with your site in internet explorer, could check this? IE still is the marketplace leader and a good component of other people will omit your magnificent writing due to this problem.|

  • hello there and thank you for your info – I’ve definitely picked up something new from right here. I did however expertise a few technical points using this web site, as I experienced to reload the website lots of times previous to I could get it to load correctly. I had been wondering if your web host is OK? Not that I am complaining, but slow loading instances times will sometimes affect your placement in google and can damage your high-quality score if advertising and marketing with Adwords. Well I am adding this RSS to my e-mail and can look out for a lot more of your respective fascinating content. Ensure that you update this again soon.|

  • 519027 651227Hey! Do you use Twitter? Id like to follow you if that would be ok. Im surely enjoying your blog and appear forward to new updates. 355625

  • 238287 727768Great post, I feel site owners need to acquire a whole lot from this web site its extremely user pleasant. 562483

  • Its like you read my mind! You seem to know so much approximately this, like you wrote the ebook in it or something. I believe that you simply can do with a few percent to force the message home a little bit, but other than that, this is excellent blog. An excellent read. I’ll definitely be back.|

  • community action twin falls idaho positive affirmations god , ivermectinsale.me [url=http://ivermectinsale.me/#Ivermectin-3-mg-for-sale]ivermectin covid[/url] social contract theory. community bridges pima community action agency pipp [url=https://bit.ly/3ahBLIB#]lyrica 25 mg forum[/url] . community bible church cut off, positive words that start with e community bank vernon ny community action agency canton ohio [url=http://www.eca.pe/obras/reparacion-de-las-instalaciones-del-museo-del-petroleo?page=3557#comment-204272]community college biology teaching jobs nd[/url] f0bc777 , positive reinforcement management [url=https://is.gd/lwoVq0#]roaccutane sin receta[/url] , followers javelin .

  • As the admin of this web page is working, no question very rapidly it will be famous, due to its feature contents.|

  • I am in fact thankful to the holder of this web page who has shared this great piece of writing at at this place.|