Knowledge of the. NET development environment, console program creation, output, input, definition variables, variable assignments, value overrides, value stitching, value printing two data types, shaping type conversion

Source: Internet
Author: User

First of all, thank Shanglikai for taking me into. NET, a good software development program. Through two days of learning in this area is also a lot of understanding, let us first understand the C # language

C # is a new, simple, secure, and fast object-oriented programming language. is a language specifically developed for. NET applications.. NET development is based on a unified development environment for Visual Studio.NET. Let's look at how to create a new project under Visual Studio.NET.

1. Open

2. Create a new project

By executing the file-new-Project menu command, a new Project dialog box pops up. Select the development language in this dialog box for C #, select the framework version (the development version here is not too high for the general selection of. NET Framework4.0), and then select the console application. Then select the saved path and file name as shown in

Now let's get to know the composition of C #

1 usingSystem//the using represents the library that the program applies to. The following system represents the console these libraries are provided by the. NET Framwork2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 6 namespaceConsoleApplication1//name Space7 {8     classProgram//class9     {Ten         Static voidMain (string[] args)//method Here calls the main function as the main function One         { A         } -     } -}

Special Note: A program can only have one entry. All program code must be written in {}.

Iii. input and output of the console program

1 usingSystem;//the using represents the library that the program applies to. The following system represents the console these libraries are provided by the. NET Framwork2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 6 namespaceConsoleApplication1//name Space7 {8     classProgram//class9     {Ten         Static voidMain (string[] args)//method Here calls the main function as the main function One         { AConsole. WriteLine ("Han Enterprise is my home");//will appear in the console as "Han Enterprise is my home" and the cursor will stay on the next line -Console.ReadLine ();//when you press ENTER, the cursor in the console window is moved to the next line waiting for user input -Console.ReadLine ();//Prevent program Flash-back the         } -     } -}

The results of the operation are as follows:

So if the change is Console.Write ("Here you can write what you want to show in the Window");

1 usingSystem;//the using represents the library that the program applies to. The following system represents the console these libraries are provided by the. NET Framwork2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 6 namespaceConsoleApplication1//name Space7 {8     classProgram//class9     {Ten         Static voidMain (string[] args)//method Here calls the main function as the main function One         { AConsole.Write ("Han Enterprise is my home");//will appear in the console as "Han Enterprise is my home" and the cursor will stay in the bank -              -Console.ReadLine ();//when you press ENTER, the cursor in the console window is moved to the next line waiting for user input theConsole.ReadLine ();//Prevent program Flash-back -         } -     } -}

The results of the operation are as follows:

Here to show you that there are two types of input statements

1.console.writeline ("Here you can write what you want to show in the Window");

2, Console.Write ("Here you can write what you want to show in the Window");

The difference between the two is whether to wrap the line automatically

So what's the input, and we'll look at the input statement.

Console.ReadLine (); When you run the cursor will wait for user input, and then press ENTER to jump to the next line. Let's take a look at the running results

Four: definition, assignment and splicing of variables

1. Definition and assignment of variables

1     class Program2     {3         Static voidMain (string[] args)4         {5             stringA//Defining Variables6A ="I'm an IT guy.";//assign a value to a variable I'm an IT guy.7Console.WriteLine (a);//print output to the value assigned to variable a8 console.readline ();9         }Ten}

Several variables can also be defined directly in the process of defining variables, for example: string A,b,c,d,......; This is also possible, but the middle is separated by commas, (in the English state, the number) in this process must be aware that only the first definition to assign value, there is also need to figure out what type of variable is to be defined, where the string type belongs to all the variables of the strings, But if there's a plus sign between the variables it defines, it's just stitching instead of adding, let me give you an example.

1 namespaceConsoleApplication12 {3     class Program4     {5         Static voidMain (string[] args)6         {7             stringA//Defining Variables8A =" the";//assign a variable to a value of9             stringb;Tenb =" -"; One             stringc = a + B;//You can also define variables like this AConsole.WriteLine (c);//print output to the value assigned to variable a - console.readline (); -         } the     } -}

It runs as a result of

So when doing the calculation if the definition of a string must not be directly used + the effect is splicing, now there is a problem out of the number of subtraction how to do, it is necessary to use other data structure to define, in fact, there are two ways

The first is to directly define an integer variable with an int

The second is to transform the variable of the string type into an integer variable.

First look at the direct definition of an integer variable if the result of "+" is used

1 namespaceConsoleApplication12 {3     class Program4     {5         Static voidMain (string[] args)6         {7             intA//Defining Variables8A = the;//assign a variable to a value of9             intb;Tenb = -; One             intc = a + B;//You can also define variables like this AConsole.WriteLine (c);//print output to the value assigned to variable a - console.readline (); -         } the     } -}

The running result is obviously an addition operation.

Look at the conversion again

1 namespaceConsoleApplication12 {3     class Program4     {5         Static voidMain (string[] args)6         {7             stringA//Defining Variables8A = Console.ReadLine ();;//Assign the user input information to a, note that a string is returned9             intb=int. Parse (a);//calling parse in int converts a string type A to an integer, which is an int typeTen             intc = B +Ten; OneConsole.WriteLine (c);//print the value of output C A console.readline (); -         } -     } the}

Note the conversion of Line 9th

The results are identical.

It is not difficult to find in the definition of the string type must remember to write "", and the definition of integer variables do not have to directly write the number on the line, it is important to remember that the variables are defined before using

Five, C # in the first + +, after the difference between

1, through examples to explain

namespaceplus sign {classProgram {Static voidMain (string[] args) {            intA =Ten;//define and assign a value to a            intb = ++a;//the value of a is called before it is added and then assigned to B.Console.WriteLine ("a="+a); Console.WriteLine ("b="+b);                   Console.ReadLine (); }

It runs as a result

2. Check after + +

1 namespaceKnowledge Supplement2 {3     class Program4     {5         Static voidMain (string[] args)6         {7 8             intA =Ten;//define and assign a value to a9 Ten             intb = a++;//the value of call a is first assigned to B and then a in self-addition; OneConsole.WriteLine ("a="+a); AConsole.WriteLine ("b="+b); - console.readline (); -             the         } -     } -}

The operation results are as follows

Why this result, is because the program is a sentence in the execution of a sentence in front of the + + in the first give yourself +1, and then give their value to B, and + in the next is the value of their own to B, and then give themselves +1, in short a word + + in the front is used to add, + + after the use of self

Knowledge of the. NET development environment, console program creation, output, input, definition variables, variable assignments, value overrides, value stitching, value printing two data types, shaping type conversion

Related Article

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.