Don't know the name of this article is right, let's call it that. I used c to write programs almost rarely use function calls to solve the problem, are using global variables and then process-oriented data to do simple processing, which caused me to learn [email protected] still have this problem, When it's better, there's a function call that writes all the classes in the default class of Program.cs, knowing that it's not standard, but it's not trying to mend it. Today a class is decided to create a new *.cs.
First, there is one project in a solution, and a project has only two classes for example.
The document organization chart looks like this:
The first class is also the default class of Program.cs, which includes the main function, the entire project is simply to calculate the addition, the code is as follows:
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespacethe invocation of the class8 {9 class ProgramTen { One Static voidMain (string[] args) A { -Console.WriteLine ("Please enter the first addend:"); - stringADD1 =console.readline (); theConsole.WriteLine ("Please enter the second one to be addend:"); - stringADD2 =console.readline (); -Addmethod Myadd =NewAddmethod (); -Console.WriteLine ("{0}+{1}={2}", Convert.todouble (ADD1), Add2,myadd.add (Convert. ToDouble (ADD1), Convert. ToDouble (ADD2)); + convert.todouble (ADD1); - Console.readkey (); + } A } at}
Program.cs
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespacethe invocation of the class8 {9 Public classAddmethodTen { One Public DoubleADD (DoubleXDoubley) A { - returnx+y; - } the } -}
AddMethod.cs
It is important to note that the name of the class document does not have to be consistent with the class name in the document code as in Java, but it is best to be consistent and the class name must not conflict with the keyword. If you feel that the class document name is not appropriate to change, you can directly rename the class document name in the document organization chart, and find that the corresponding class name in the document is also automatically modified (version VS2012).
It's also important to note that like
String add1 = Console.ReadLine ();
Console.WriteLine ("{0}+{1}={2}", Convert.todouble (ADD1), Add2,myadd.add (Convert). ToDouble (ADD1), Convert. ToDouble (ADD2));
These control statements are not written in the new class and are written directly in the main function.
C # novice 1-How to organize classes and call each other