Mike old cat comes from: the ideal of the old cat
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. Continue to go back, the array is usually used, I will introduce: arrays are a set of data with the same type. When the data in the array can be accessed, it can be specified by the subscript. The C # medium array element can be any data type, the array subscript starts from 0, that is, the first element corresponding to 0, and increment one by one. An array can also be multi-dimensionally.
/ / Contain one-dimensional integer array of six elements;
INT [] mf1 = new int [6]; // Note the range of initialization array, or specify the initial value;
/ / Contain one-dimensional integer array of six elements, initial value 1, 2, 3, 4, 5, 6
INT [] MF2 = New Int [6] (1, 2, 3, 4, 5, 6);
// One-dimensional string array, if the initial value setting item is provided, the NEW operator can also be omitted
String [] MF3 = {"C", "C ", "C #"};
// One-dimensional object array
Object [] mf4 = new object [5] {26, 27, 28, 29, 30};
// Two-dimensional integer array, initial value MF5 [0,0] = 1, MF5 [0, 1] = 2, MF5 [1,0] = 3, MF5 [1, 1] = 4
Int [,] mf5 = new int [] {{1, 2}, {3, 4}}
// 6 * 6 two-dimensional integer array
int [,] mf6 = new mf [6,6];
Let's take a look at the traversal of a one-dimensional string array.
Using system;
Public Class Mikecat
{
Static void PrintArray (String [] ARR)
{
/ / Print the array element, arr.length represents the number of array elements
For (int i = 0; i { Console.writeLine ("Arr [{0}] = {1}", I, Arr [i]); } } Public static void main () { String [] arr = {"c", "c ", "c #"}; // Transfer the array as a parameter PrintArray (arr); } } Procedure: Arr [0] = C Arr [1] = C Arr [2] = C # Let's take a look at a 4-line 2 column (4 * 2) traversal: Using system; Public Class Mikecat { Static void PrintArray (int [] Arr) { / / Through two FOR cycles, two-dimensional array For (int i = 0; i <4; i ) // initialization I acts as a loop variable, i implements the self-increment operation of the variable. // for loop After satisfying the condition, execute i after performing the cyclic body, then enter the next loop. Simple C Syntax, here is simple introduction to take care of beginners. (For details, please refer to Mr. Tan Haqiang's C language program design book) { For (int J = 0; j <2; j ) { Console.writeline ("Arr [{0}, {1}] = {2}", i, j, arr [i, j]); // Print each 2D array element } } } Public static void main () { // master function // Transfer the array as a parameter PrintArray (new int "{{1, 2}, {3, 4}, {5, 6}, {7, 8}}; } Run results: Arr [0,0] = 1 Arr [0,1] = 2 Arr [1,0] = 3 Arr [1, 1] = 4 Arr [2, 0] = 5 Arr [2, 1] = 6 Arr [3,0] = 7 Arr [3,1] = 8 Class is the basic texture block for object-oriented programming, and we will introduce later. Here we introduce two special classes, ie Object classes and String classes 1.Object class The Object class is an alias for a predefined class System.Object, which is all other types of base classes. All types in C # are inherited directly or indirectly from the Object class. Therefore, the variable of an Object class can give any type of value. INT i = 30; Object obj1; Obj1 = i; Object obj2 = 'a'; 2.String class The String class is specifically used to operate the string, he is an alias for the predefined class system.string String str1 = "mikecat"; Two strings can be connected with the " " number. String str2 = "Username:" "mikecat"; If you access a single character, you have to use it. CHAR C = STR1 [0]; Compares whether the two strings are equal, and the comparison operator "==" // is different from the Basic syntax BOOL B = (str1 == Str2); In C #, the most flexible use of C and C is also the most hard-to-master pointer. So how do you provide function pointers in C / C in C #? C # provides delegate, which is a reference type inherited from the System.Delegate class. It is equivalent to a function pointer. Unlike functional pointers, commissioning in C # is type security, delegate, especially suitable for anonymous calls. It is necessary to use the entrustment to pass three steps, namely, statement, instantiation, calling. Using system; // Declare a delegation named MFDelegate, which has a string type parameter // C # compiler generated a new class, which inherits from System.deLegate, class // named MFDelegate Public delegate void mfdelegate (String name); Public Class Mikecat { // Define the method of having the same parameter type with mfdelegate Hello () Public static void Hello (String Name) { Console.writeline ("Hello, {0}!", Name); } // Define how the same parameter type with mfdelegate is Goodbye () Public Static void Goodbye (String Name) { Console.writeline ("Goodbye, {0}!", Name); } Public static void main () { // Create a MFDelegate instance MF1 Mfdelegate MF1 = New MFDelegate (Hello); // Call MF1 MF1 ("mikecat"); MFDelegate MF2 = New MFDelegate (Goodbye); MF2 ("Mikecat"); // combine the MF1 MF2 into a new commission MF3 MFDelegate MF3 = MF1 MF2; // call MF3 MF3 ("Mike Old Cat"); // Remove MF1 from the combination of entrusted MF3 MFDelegate MF4 = MF3-MF1; MF4 ("Mikecat"); } } Procedure: Hello, Mikecat! // MF1; Goodbye, Mikecat! // MF2 Hello, Mike Old Cat! Goodbye, Mike Old Cat! // MF3 Goodbye, mikecat! // mf4