Hey guys,
I added a class to my project and called it MyCustomClass, now in my main class I initialize it by saying
MyCustomClass test = new MyCustomClass;
What I am trying to do is when I create this class I want it to automatically run a default method that will do bunch of stuff.
with java I had a Main method that will happen whenever a class is created, I am trying to figure out what this method is with C# and how do I create it. So if you are familiar with java I am looking for public static void main(String [], args) method.
Yeah its a really dumb question, I just couldn't find the answer on google...
Thanks for the help.
Loading

VulpesRank #55 · 29.2K reputationPosted Oct 20, 2012, 3:10 PM EDT
If you want a method to run automatically when you create an object of your class, then you need to call it from the constructor. For example:
bagzli36 reputationPosted Oct 21, 2012, 8:20 AM EDT
VulpesRank #55 · 29.2K reputationPosted Oct 21, 2012, 8:53 AM EDT
Console.ReadKey() simply waits for the user to press a key. If (as most folks do) you're running a console application in debug mode using Visual Studio, then you'll find that the console window will close before you've had time to read the output. Adding Console.ReadKey() at the end of the program is one way to prevent this from happening.
bagzli36 reputationPosted Oct 27, 2012, 2:43 PM EDT
Cheers,
Bagzli