C # novice 1-How to organize classes and call each other

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.