. NET Foundation of 2--c# Foundation

Source: Internet
Author: User

1, the role of the annotation character

1), write-off 2), explain

2.3 kinds of interpreters in C #

1), single-line comment (//the content to be annotated )

// The purpose of this line of code is to output Hello World to the console Console.WriteLine ("hello,world! " ); // The purpose of this line of code is to pause the current program Console.readkey ();

2), Multiline comments (/* content to be annotated */)

            /*             Console.WriteLine ("hello,world!");            Console.WriteLine ("hello,world!");            Console.WriteLine ("hello,world!");            Console.WriteLine ("hello,world!");            Console.WriteLine ("hello,world!");            Console.WriteLine ("hello,world!");              */

3), Documentation Comments (///More used to interpret classes or methods)

        /// <summary>        ///The function of this method is to find the maximum value between two integers/// </summary>        /// <param name= "N1" >First integer</param>        /// <param name= "N2" >a second integer</param>        /// <returns>return the larger number.</returns>         Public Static intGetmax (intN1,intn2) {            returnN1 > N2?n1:n2; }
    /// <summary>    ///This class is used to describe a person's information, from name, gender, age description/// </summary>     Public classPerson { Public stringName {Get; Set; }         Public intAge {Get; Set; }         Public CharGender {Get; Set; }    }

Common shortcut keys in VS

Ctrl+k+d: Quick Alignment Code

CTRL + Z: Undo

Ctrl+s: Save

Ctrl+j: Smart Tips

Shift+end, Shift+home:

Ctrl+k+d: Comment Code

Ctrl+k+u: Uncomment code

F1: Go to help documentation

#region和 #endregion: Folding Redundant code

3. Variables

Used to store data in the computer.

storing integers 100

Data type: integer

The space type opened in memory should be an integer type int

Syntax for storing variables: variable type variable name;

Variable name = value;

            // Variable type   variable name             // variable                         name = value //+//  Official language: Declares or defines an integer variable int number of type int             ;   creates            a space // official language in memory that can store integers : Assign this variable to a value of               It means to store 100 in this space.

4. Data type

1), integer type: int can only store integers. Cannot store decimals

2), decimal type: Double can store both integers and decimals. Number of digits after the decimal point 15-16 bits

3), Money type: Demical used to store money, after the value to add a M

4), String type: String to store multiple text, or to store empty. String type values need to be enclosed in double quotes

5), character type: char is used to store a single character, up to a minimum of one character, and cannot be stored empty. The value of the character type needs to be enclosed in single quotation marks.

            intn =3; DoubleD =3.14; //Zhang San, John Doe, Harry, ABCDSF            stringZsname ="Zhang San"; strings ="";//string can store empty//string character kebab and mutton            CharGender='male'; decimalMoney = 500m;

5. Wavy Line

1), Red--"syntax error in code"

2), Green--"error may occur in code, but not necessarily error

6. Rules for the use of variables

If you want to use a variable, declare the value and then use it.

7. Naming rules

The first thing to make sure is that the name of the variable is meaningful.

1), at this stage to the name of the variable can start with a letter

2), followed by any letter, number, underline

Note: 1), your variable name does not repeat with keywords in C # system

2), in C #, casing is sensitive

3), with a variable name is not allowed to repeat the definition (first thought, not rigorous)

Two naming conventions are required to name a variable:

1), Camol: Camel naming rules. Require the first letter of the first word of the variable name to be lowercase, and the first letter of each of the remaining words to be capitalized. Many are used to name variables.

2), Pascal: Requires the first letter of each word to be capitalized, the remaining letters lowercase. Many are used to name classes or methods.

8. Assignment operators

=: Indicates the meaning of the assignment. An expression joined by an equal sign is called an assignment expression.

Note: We can solve a fixed value for each expression.

9, + number of the role

1), connect: + sign can connect two strings.

2), add: Both sides are numbers.

            string " Harry " ;            Console.WriteLine (" Hello," + name);            Console.readkey ();
Console.WriteLine (5"5"); Console.readkey ();
            //when a guy named Kakashi in a hotel, he was asked to fill out a form at the front desk .//The contents of these tables are to be stored on the computer//name, age, mailbox, home address, salary//And then I'll show you the information.            stringName ="Kaka West"; intAge = -; stringemail ="[email protected]"; stringAddress ="Fire Shadow Village"; decimalSalary =5000m; Console.WriteLine ("My name"+ name +", I live in"+ Address +", I this year"+ Age +", my mailbox is"+ Email +", my salary"+ Salary +". "); Console.readkey ();
int  -  Bayi; Console.WriteLine (" you are all " " old "); Console.readkey ();

10. Placeholder

How to use: First dig a hole, then fill a hole.

            intN1 =Ten; intN2 = -; intN3 = -; //Console.WriteLine ("The first number is:" +n1+ ", the second number is:" +n2+ ", the third number is:" +n3);Console.WriteLine ("The first number is: {0}, the second number is: {1}, the third number is: {2}", N1,N2,N3);//Print out 10,20,30Console.WriteLine ("The first number is: {1}, the second number is: {0}, the third number is: {2}", N1, N2, N3);//Print out 20,10,30Console.readkey ();

Places to be aware of using placeholders:

1), you dig a few pits, you should fill a few pits. More fill out no effect, less fill the throw exception.

2), the order of output: according to the order of digging pits output.

1             //define four variables to store one person's name, gender (Gender), age, Phone2             //(telephonenumber). And then print it on the screen (my name is X, I'm x years old, I'm x born,3             //my phone is xx) (phone number with what type, such as: 010-12345)4             stringName ="Yiping";5             CharGender='female';6             intAge = -;7             stringTelephonenumber ="010-12345";8Console.WriteLine ("my name {0},{1}, this year {2} years old, the phone is {3}", Name, Gender, age, telephonenumber);9Console.readkey ();

11. Abnormal

Exceptions are grammatical irregularities, except in the course of a program's operation, which, for some reason, can no longer function properly.

12. Escape character

Definition: The escape character refers to a ' \ ' + a special character that makes up a character with a special meaning.

\ n: Indicates a line break.         \ ': Represents an English half-width double quotation mark. \ t:: Represents a space for a TAB key.

Console.WriteLine (" nice and sunny weather today "); Console.readkey ();
Console.WriteLine (" I want to output a Chinese half-width double quote" "In this sentence);  // "" Console.WriteLine (" I want to output an English half-width double quotation mark in this sentence," \ ");  //   ""Console.readkey ();
stringName1 ="Zhang San";stringName2 ="It's a non-conformance .";stringName3 ="US Retro First";stringName4 ="The woman came to see the teacher."; Console.WriteLine ("{0}\t\t{1}", name1, name2); Console.WriteLine ("{0}\t{1}", Name3, name4); Console.readkey ();

\b: Represents a backspace key that has no effect on either side of the string.

Console.WriteLine ("In the end \b is which word disappeared?") ");   // which word has gone missing? Console.readkey ();

\ r \n:window operating system do not know \ n, only know \ r \ n.

string " The weather is fine today. \ r \ n everywhere good scenery. ";            System.IO.File.WriteAllText (@ "C:\Users\Administrator\Desktop\111.txt", str); // creates a new file in which the specified string is written, overwriting the file if the file already exists. Console.WriteLine (" write succeeded! ");

@ symbol: 1), cancel \ Escape function in string. So that it is simply represented by a \.

2), the string is given in the original format.

            string @" F:\hhhj\jshk\a\b\c\ Learning C # transfer character @ " ;            Console.WriteLine (path);            Console.WriteLine (@ " today is fine and sunny everywhere good scenery ");            Console.readkey ();

13. Arithmetic Operators

+,-, *,/,%

14. Type Conversion

Implicit type conversions:

We require that the operands on both sides of the equal sign must be consistent, some inconsistencies, and that an automatic type conversion is sent, called an implicit type conversion, if the following conditions are true.

1), two types of compatibility. For example, int and double are compatible (both numeric types).

2), the target type is greater than the source type. For example: double > Int. A small, big turn.

Display Type conversions:

1), two types of compatible int------double

2), large small double-----int

Syntax: (the type to be converted) The value to convert

If one operand is of type double, the entire expression can be promoted to a double type.

. NET Foundation of 2--c# Foundation

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.