C# Basic (1)

1. String str = System.Console.ReadLine();

cause the application to pause until you have pressed the Enter key. Insert this line before the end of each application.

2.Main

Every C# application must have a method named Main defined in one of its classes. It doesn’t matter which class contains the method—you can have as many classes as you want in a given application—as long as one class has a method named Main. In addition, this method must be defined as public and static. The public keyword is an access modifierthat tells the C# compiler that anyone can call this method.  the static keyword tells the compiler that the Main method is a global method and that the class does not need to be instantiated for the method to be called.

Mostly, the main method is in Program.cs

3. Namespace

System.Console.WriteLine(“Hello, World”); =using System; class HelloWorld { public static void Main() { Console.WriteLine(“Hello, World”); } }When the compiler parses the Console.WriteLine method, it will determine that the method is undefined. However, it will then search through the namespaces specified with the using directives and, upon finding the method in the System namespace, will compile the code without error.

4.using for namespace and alias

using ouput = System.Console; class HelloWorld { public static void Main() { output.WriteLine(“Hello, World”); } }

(It’s like the C++ include, I guess)

5. Errors

For VS2010, we usually see the output tag, at the same line, there is Error list tag, that’s for finding errors.

Advertisements
This entry was posted in C#. Bookmark the permalink.

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