C # Study Notes ---- core C #

Source: Internet
Author: User
Tags case statement

All the work done in C # depends on the. NET base class.

 

Variable

C # There are two ways to ensure that the variables are initialized before use:

Variables are fields in a class or structure. If they are not explicitly initialized, the default value is 0 when these variables are created.

. Local variables of the method must be explicitly initialized in the code before their values can be used in the statement.

 

Type inference uses the VaR keyword

 

Constant keyword const

Constants have the following features:

. Constants must be initialized during Declaration

The constant value must be used for computation during compilation.

. Constants are always static and do not need or allow include modifiers static

 

Predefined Data Types

The value type is stored in the stack, and the reference type is stored in the managed stack.

Example of reference type:

Vector X, YX = new vector (); X. value = 30; // value is a field defined in vector classy = x; console. writeline (Y. value); Y. value = 50; console. writeline (X. value); // The output result is 30, 50

 

C # There are 15 predefined types, 13 of which are value types and 2 are reference types (string and object)

In C #, the object type is the final parent type.

 

Escape Character '/'

'@' Cancel escape characters

 

Flow Control

Switch statement: the switch... case statement is suitable for selecting an Execution Branch from a group of mutually exclusive branches.

The value of case must be a constant expression. Variables cannot be used.

 

The C # For Loop provides an iterative Loop Mechanism to test whether a condition is met before the next iteration is executed.

While is also a predictive loop, while a loop has only one expression

Do... while is the post-test version of the while loop. The testing condition of this loop must be executed after the loop is executed.

The foreach loop can iterate each item in the set.

 

Jump statement:

. Goto

. Break exit Loop

. Continue exit current iteration of the loop

. Return

 

EnumerationIs a user-defined Integer type

 

Namespace

The Using Keyword can be used to specify aliases for classes and namespaces.

Note that the namespace alias modifier ":"

 

C # Compilation

C # command line compiler csc.exe (environment variables need to be set)

/Target (Abbreviation/T) specifies the file type to be created

 

/T: EXE console application (default)

/T: library with a list of Class Libraries

/T: component without a list

/T: winexe windows application (no console window)

 

/Out specifies the output file name generated by the compiler.

/Reference or/r Reference Type in the unreferenced assembly

/Doc xml document

 

Note

XML format tag:

<C> MARK text in a row

<Code> MARK multiple lines as code

<Example> mark as a sample code

<Exception> An exception class (the compiler needs to verify its syntax)

<Include> annotations containing other document description files (the compiler needs to verify its syntax)

<List> Insert the list to the document.

<Param> mark method parameters (the compiler needs to verify its syntax)

<Paramref> indicates that a word is a method parameter (the compiler needs to verify its syntax)

<Permission> access to members (the compiler needs to verify its syntax)

<Remarks> Add a description to a member

<Returns> return value of the Method

<See> provides cross-reference for another parameter (the compiler needs to verify its syntax)

<Seealso> the "Participate" section in the description is provided (the compiler needs to verify its syntax)

<Summary> provides a brief summary of types or members.

<Value> description attribute

 

Preprocessing commands

# Define debug indicates that the compiler has a given name symbol

# UNDEF debug Delete the definition of a symbol

# If # Elif # else # endif these commands tell the compiler whether to compile a code block

# Warning and # error compilers generate warnings and errors

# Region and # endregion Layout

# The line command can be used to change the file name and line number information displayed by the compiler in the warning and error messages.

# The Pragma command can suppress or restore specified compilation warnings.

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.