C # basic review 01,

Source: Internet
Author: User

C # basic review 01,

I'm about to graduate soon. I'm going to sort out the knowledge I 've learned over the past few months. I 've written some basic things in C #. (Don't laugh at me, I want to help some people who are learning this knowledge. If something is wrong, I hope you can give me some advice.

Let's start with the basics:

1: c # is a strongly typed language. It is case sensitive and must have a clear definition of the variable type.

2: The value assignment operator "=": equal signs in c # do not mean equal, but assign values. assign values on the right of equal signs to the variables on the left of the equal signs, and the expressions connected by equal signs, it is called a value assignment expression. The Data Types on both sides of the equal sign must be consistent.

3: Use the plus sign: ① To connect. When one side of the plus sign is a string, the plus sign serves as a connection. ② When both sides of the plus sign are numbers, the plus sign serves as the sum.

4: Use of placeholders: use rules: first open a pit and then fill in a pit.

Note: If you have dug a few pits, you can fill them out. If you do not fill them out, the program will throw an exception. If you do not fill them out, the program will output them in the order of digging.

5: Escape Character: the so-called escape character refers to a '\' with a special character, forming a special character.

\ B: indicates the return key.

\ ": Represents a double quotation mark.
\ N: line feed
\ R \ n: Indicates line feed in the operating system
\ T: the effect is the tab key on the keyboard.
\: Represents '\'

 

@ Symbol: Cancel escape: cancel the escape Function of '\' in the string, so that it is simply expressed as a '\'; let the code output according to the original format of the editing.

6: Arithmetic Operator: an expression connected by an arithmetic operator, called an arithmetic expression (which is generally understandable ).

+
-
*
/
%

 

 

7. type conversion: In an arithmetic expression, the Data Types of equal signs and edges must be consistent. If they are inconsistent and meet the following two conditions, automatic type conversion and implicit type conversion will occur.

1) The two types must be compatible (both numbers) double int

2) convert from small to large int ---> double

The compiler automatically helps us complete the conversion.

 

8: Forced type conversion or display type conversion

1) The two types must be compatible (both numbers) double int

2) convert a large value to a small double ---> int

Eg:

Int a = 10;
Double d = 20;
Int B = a + (int) d;
Console. WriteLine (B );

Note: precision will be lost in the result of forced type conversion.

 

9: Convert type conversion: used to handle conversions with incompatible types.

Int type: Convert. ToInt32 (Object );

Double Type: Convert. ToDouble (Object );

String: ToString ();

 

Finally, let's give a small question to the partner who learns the basic knowledge. (before reading the answer to this question, you can first think about the question that you did not make in five minutes... It's not enough to catch up with me)

Programming for 86400 seconds (no matter how many seconds) is a few days, hours, or minutes?

The answer is as follows:

 

 

 

 

 

 

 

 

Int seconds = 86400;
Int days = seconds/86400; // returns the number of days.
Int secs = seconds % 86400; // number of seconds remaining after the number of days
Int hours = secs/3600; // obtain the hour
Secs = secs % 3600; // the remaining number of seconds after the end of the hour
Int mins = secs/60; // minute
Secs = secs % 60; // the last remaining seconds
Console. WriteLine ("{0} seconds are {1} days {2} hours {3} minutes {4} seconds", seconds, days, hours, mins, secs );
Console. ReadKey ();

 

  

Write this point first, and it will continue to be updated ......

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.