One week learn C # (preface)

Source: Internet
Author: User
Tags definition expression
One week learn C # (preface)

C # Bird (qq:249178521)

4. Punctuation Marks

{and} constituent statement blocks

A semicolon represents the end of a statement

Using System;

public sealed class Hiker

{

public static void Main ()

{

int result;

result = 9 * 6;

int thirteen;

thirteen = 13;

Console.Write (Result/thirteen);

Console.Write (result% thirteen);

}

}

A C # "class/struct/enum" definition does not require a terminating semicolon.

public sealed class Hiker

{

...

//No; it's right.

However, you can use a terminating semicolon but have no effect on the program:

public sealed class Hiker

{

...

}; Yes, it's OK, but not recommended.

In Java, the definition of a function can have a trailing semicolon, but is not allowed in C #.

public sealed class Hiker

{

public void Hitch () {...}; ; it's not true.

//No; it's right.

5. Statement

Declaration is the introduction of variables in a block

U each variable has an identifier and a type

U the type of each variable cannot be changed

Using System;

public sealed class Hiker

{

public static void Main ()

{

int result;

result = 9 * 6;

int thirteen;

thirteen = 13;

Console.Write (Result/thirteen);

Console.Write (result% thirteen);

}

}

It is illegal to declare a variable: This variable may not be used. For example:

if (...)

int x = 42; Compile-time error

Else

...

6. Expression type

The expression is used for calculation!

W each expression produces a value

W Each expression must have only unilateral effect

W each variable can be used only if it is assigned a value

Using System;

public sealed class Hiker

{

public static void Main ()

{

int result;

result = 9 * 6;

int thirteen;

thirteen = 13;

Console.Write (Result/thirteen);

Console.Write (result% thirteen);

}

}

C # does not allow any one expression to read the value of a variable unless the compiler knows that the variable has already been initialized or has been assigned a value. For example, the following statement causes a compiler error:

int m;

if (...) {

m = 42;

}

Console.WriteLine (m);//Compiler error, because m may not be assigned

7. Take the value

Type fetch value explanation

BOOL True False Boolean

Float 3.14 Solid Type

Double 3.1415 bi-precision

Char ' X ' character type

int 9 Integral type

String "Hello" strings

Object NULL objects


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.