Benjamin Ashton

Benjamin Ashton

  • NA
  • 15
  • 7.4k

The difference between declaring something and making it equal to a new?

Jul 11 2012 6:37 AM
I am quite new to C# and am moving over from a mediocre knowledge of Pascal, so theres quite a bit new construct to learn. There is probably 2 very simple answers to my questions, but I have done some research and have not found any explanation I can relate too, so I would be grateful if someone could help me out.

First Question 
What is the difference between declaring something with just its type and declaring it as well as making it equal to a "new" of the same type?

        //Simple declaration 
Int myInteger;       
Random myRand;
        //Making it equal to the same type
Int myInteger = new Integer();
Random myRand = new Random();

Second Question
I am fully trying to understand how Static works, but struggling and just end up making everything static because you need static variables inside your static main and so on. I know its something to do with only running the program once, but would really need a simple and clear explanation of it before I can move on to fully understanding the complications of it, maybe a with a metaphor would help.

Thanks for the help, and I look forward to replies!

Answers (7)