This tutorial references to the C # and the ASP.NET programming tutorial, what is wrong, please point out, or in the ideal blog of the old cat. First explain C #, here is just a rough explanation, please purchase relevant books, or see related documents. C # has canceled the pointer in C , and a large number of operators (:: ->) in C are already unable, and the C # is supported by ".". C # has all features of object-oriented programming languages such as encapsulation, inheritance, polymorphism. And more objects more than Java, each type can be seen as an object. But C # means allowing a single inheritance, that is, a class does not have multiple base classes. In addition, C # has no full-class function, no global variable, and has no global constant. Everything must be packaged in a class. Let's take a small example of a console application: use system;
Class Mikecat
{
Public static void main ()
{
Console.Writeline ("Mike Old Cat C # Asp.Net Getting Started Series Tutorial - Welcome to the Old Cat");
}
}
The program is always starting from the main () method, the main () method can only be included in a class, and the type that the main () method returns can be VOID (no return value) or int (return representation application error Level integer).
The above Using System; used to import name space (Namespace) to indicate the hierarchical relationship of the class. If you don't have to import namespaces, you have to add namespaces in front of the class name each time you use a class.
The input output of the C # program is implemented by console. Console is a class under the SYSTEM name space. Output a string on the screen with console.writeline (), accept the input device's input with the console.readline () method.
code:
Class Mikecat
{
Public static void main ()
{
System.console.writeline ("Mike Old Cat C # ASP.NET Getting Started Series Tutorial - Welcome to the Old Cat's Ideal / N");
System.console.writeLine ("Please enter your username:");
String user = system.console.readline ();
System.console.writeline ("Welcome: {0}"! ", User);
}
}
The first parameter after the parameter table of the WriteLine () method will replace {0}.
If the program is passed to the application when executing the program, the format of the main () method should be:
Using system;
Public Class Mikecat
{
Public static void main (string [] args)
{
Console.writeline ("A total of {0} command line arguments", args.length);
For (int i = 0; i { Console.writeline ("arg [{0}] = [{1}]", i, args [i]); } } } C # in the single line of comments in //, multi-line comments with /*... Use constants in C #: Using system Class Mikecat { Public const double pi = 3.14; Public static void main () { Console.writeline ("The value of the percentage PI is {0}", PI); } } Structural Types (struct) is a composite data type for organizing certain related data to a new data type. Using system; Struct Mikecat { Public String Mike; // User Public uint age; // agn Public String email; // email } Class MF { Public static void main () { Mikecat zl; // Declare structure type variable ZL Zl.name = "Mike Old Cat"; ZL.AGE = 24; Zl.email = "mike@hebut.com"; Console.writeline ("Name: {0}, age: {1}, email: {2}", zl.name, zl.age, zl.email; } } The enumerated type (Enum) in the C # is a set of logically unique integers: Using system; ENUM Weekday { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }; // Note the semicolon here Class Mikecat { Static void main () { Weekday day; // Declare enumeration variable DAY Day = weekday.tuesday; Console.writeline ("The value of DAY is {0}", DAY); } } Each element type in the C # enumeration type is int Byte Long Short type, and the first element value is 0, and it is incremented by 1. In the enumeration, you can also assign a value directly, and the increment is incremented. Enum weekday: Byte { Sunday = 1, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }