For more information, see C # and ASP. NET. Program Design tutorial writing, please point out any shortcomings, or leave a message on the old cat's ideal blog.
First, I would like to explain C #. Here is a rough explanation. For details, please purchase related books or refer to relevant documents. C # has canceled the pointer in C ++ and a large number of operators (:->) used in C ++ are no longer displayed. C # supports ". ". C # object-oriented Programming Language All features, such as encapsulation, inheritance, and polymorphism. It is more object-oriented than Java, and each type can be considered as an object. However, C # indicates that a single inheritance is allowed, that is, a class does not have multiple base classes. In addition, C # has no global function, no global variable, and no global constant. Everything must be encapsulated in a class.
The following is a small example of a console application:
Using system;
Class mikecat
{
Public static void main ()
{
Console. writeline ("Mike's old cat C # Asp.net tutorials-welcome to the old cat's ideal ");
}
}
In C #, the program always starts from the main () method. The main () method must and can only be contained in one class. The type returned by the main () method can be void (no return value) or int (return an integer representing the application error level ).
The preceding using system is used to import namespace to indicate the class hierarchy. If you do not need to use using to import a namespace, you must add a namespace before the class name each time you use a class.
C # the input and output of the program are implemented through the console. Console is a class in the system namespace. Output a string on the screen using console. writeline (), and accept input from the input device using the console. Readline () method.
Program Code :
Class mikecat
{
Public static void main ()
{
System. Console. writeline ("Mike's old cat C # Asp.net tutorials-welcome to the old cat's ideal \ n ");
System. Console. writeline ("Enter the User name :");
String user = system. Console. Readline ();
System. Console. writeline ("Welcome: {0! ", User );
}
}
The first parameter followed by the string in the parameter table of the writeline () method replaces {0 }.
If you want to pass the command line parameter to the application during program execution, 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 parameters", argS. Length );
For (INT I = 0; I <args. length; I ++)
{
Console. writeline ("Arg [{0}] = [{1}]", I, argS [I]);
}
}
}
Single line comment in C # // and multi-line comment /*...*/
Use constants in C:
Using System
Class mikecat
{
Public const double Pi = 3.14;
Public static void main ()
{
Console. writeline ("the PI value of the circumference rate is {0}", Pi );
}
}
Struct is a composite data type used to organize some related data into a new data type.
Using system;
Struct mikecat
{
Public String Mike; // user
Public uint age; // age
Public String email; // email
}
Class MF
{
Public static void main ()
{
Mikecat ZL; // declare the struct type variable ZL
ZL. Name = "Mike ";
ZL. Age = 24;
ZL. Email = "mike@hebut.com ";
Console. writeline ("Name: {0}, age: {1}, email {2}", Zl. Name, Zl. Age, Zl. Email );
}
}
In C #, the enumeration type (Enum) is a set of logically inseparable integer values:
Using system;
Enum weekday
{
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
}; // Note the semicolon
Class mikecat
{
Static void main ()
{
Weekday day; // declare the enumerated variable day
Day = weekday. Tuesday;
Console. writeline ("the value of day is {0}", Day );
}
}
In C #, each element type in the enumeration type is int byte long short type, and the first element value is 0, followed by 1. In enumeration, you can also assign values to the elements, followed by increments.
Enum weekday: byte
{
Sunday = 1, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
};