I,
1. the console Program created by default has only one Program. cs, as well as Properties and references,
2. We define a new class. Another. cs
The Code is as follows:
Code
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace TestInt
{
Public class Another
{
Public void GetName ()
{
Console. WriteLine ("Hello, My name is Another ");
}
}
}
Here, we only define the Another class, but we haven't started to use it yet.
3. Use the Another class.
Go back to Program. cs and add the content.
Code
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
// The namespace name can be changed.
Namespace TestInt
{
// This class is created by default.
Class Program
{
Static void Main (string [] args)
{
// Instantiate an Another class. The instantiated variable is objAnother.
// It can also be understood as follows: Another is a "class", and objAnother is an "object" of the class (a "Replica" or "instance ").
// "Class", "object", and "instance" are all nouns. It is okay to know this meaning.
Another objAnother = new Another ();
// We can "instantiate" more Another objects
Another objAnother1 = new Another ();
Another objAnother2 = new Another ();
// Obtain the name:
ObjAnother. GetName ();
// Output: Hello, My name is Another
Console. ReadLine (); // stop the output screen for a while. Wait until you press any key and close it.
}
}
}
Press F5 to run,
Expected result:
OK, it's over
Ii. Use debugging to check the execution sequence:
1. Place a breakpoint for the Another class
2. Place a class in Program. cs:
3. Press F5, for example:
4. Press F10,
Press F10.
OK, my story is over.