C # concise tutorial (6) --- Create the first C # project

zhaozj2021-02-17  94

C # concise tutorial

Establish the first C # project (Project)

This article will take a step to guide you to complete your first C # project.

Step 1: Production of an empty C # project

Select File-> New-> Project-> Visual C # Projects-> Visual C # Projects-> Visual C # Projects-> Empty Project. Add your project name and select a suitable directory through the Browse button. As shown below:

Step 2: Add an empty class to it

Right-click your project in Solution Explorer and click Add-> Add Class

You will see this dialog box below. Here, you can add a variety of classes to your project. We now add a C # class. Fill in the name of your class and click Open.

Now, you have added a class for your project. Visual Studio generates a framework for your class, just like this:

Namespace DownloadWeb {Using System; ///

/// Summary Description for McClass. /// public class mcclass {public mcclass () {/// Todo: add constructor logic here //}} }

Step 3: Add functions to class

It is now added to the class now. Insert the following code, add a few functions, and call them in the main function.

Namespace DownloadWeb {USING SYSTEM; ///

/// summary description for mcclass. /// public class mcclass {// Seeking 2 times public int square (int Num) {Return Num * NUM; } // Two integers addition, return and public int add (int Num1, int Num2) {RETURN NUM1 NUM2;} // Two double precision numbers, return, and public Double Add (double number, double num 2) {RETURN NUM1 NUM2;} // Two integers multiplied, return to the product public int multiPly (int Num1, int Num2) {return Num1 * Num2;} // large number reduction, return Public Int subtract (int Num1 , int Num2) {IF (Num1> Num2) {RETURN NUM1 - Num2;} Return Num2 - Num1;}}

// Call class McClass from Main

Public class class1 {static void main () {mcclass sq = new mcclass (); console.writeline (sq.square (8) .tostring ()); console.writeline (SQ.Add (8.3, 9.24) .tostring () ); Console.writeline (Sq.Multiply (5, 8) .tostring ()); console.writeline (Sq.Subtract (22, 42) .tostring ());}}}

Step 4: Establish and run the project

转载请注明原文地址:https://www.9cbs.com/read-31371.html

New Post(0)