Static – What a wonderful word

I finally figured out how to use variables in more than one form, and its all thanks to the word “static”

C# does not have global variables like C/C++ or VB, and static has taken its place and increased the safety of using global or staic variables.

This means that now i can get pretty much everything done that i need to for my open day, hopefully by the end of this week. Today i chose where i’ll be showing it off to, on the open day and the colour card for my poster too, its all starting to seem very close. But i feel confident about getting the work done, as long as i dont run into to many more problems like that one.

I’d also like to say thanks to nnxion for guiding me in the right direction on, althought no-one else there helped me out at all.

I’ve got a few titbits coming later tonight, but right now i need some caffine and visual studio :P


4 thoughts on “Static – What a wonderful word”

  1. If you want to be fancy, the full belt-and-braces (and thread safe I may add) approach is to use a Singleton class with accessor methods. That way there’s only every one, but you don’t have problems if you need to remove the hosting class for the static variable.

    Yell if your interested and I’ll throw you some code.

  2. To be more accurate, static variables (and static methods for that matter) are those that do not require you to create an instance of the class in which they are contained in order to use them.

    I agree with Russ though, I do tend to create public static properties via accessors, with a private backing field in the class they belong to.

    But I don’t wanna bog you down with heavy OO esoterica at this stage of your C# journey……

    [Atari stuff/C# stuff/IT Crowd – OMG I’m turning into AtariBoy!]

  3. Yeah, i was a bit conserned with using them, especially with all the warnings i saw (including in the MSDN help!), but with only 2 and a bit weeks left to get a working alpha to show on my open day im not to conserned about how thread safe it is.

    If i continue to develop the program after my course then i will make use of singleton class, but for the moment it works and doesnt crash anything so its not too much of a problem.

    I’m trying to “sell” the concept rather than the code itself.

    Thanks for your help tho guys, at least i now known two people to run too if i need help!

Leave a Reply

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

You are commenting using your 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