C # review ②,

Source: Internet
Author: User

C # review ②,

C # review ②

June 15, 2016

1. C # Symbols

Identifier = (letter | '_' | '@') {letter | digit | '_'}.

Note:

1. Unicode encoding

2. Case Sensitive

3. @ again to specify the symbol or symbol

If ...... Keyword

@ If ...... Identifier if

 

2. Naming rules Naming Conventions

Recommended blog: http://blog.sina.com.cn/s/blog_735f1bcd01017rer.html

PascalRules

Uppercase letters (such as TestCounter) Starting with each word ).

CamelRules

The START Letter of other words except the first word is in uppercase. For example,. testCounter.

UpperRules

It is used only for the abbreviation of a constant of one or two characters long. The Pascal rule should be applied for the length of more than three characters.

 

Identifier

Case sensitivity

Example

Class/Structure

Pascal

AppDomain

Enumeration type

Pascal

ErrorLevel

Enumerated Value

Pascal

FatalError

Event

 

Pascal

 

ValueChange

Exception

Pascal

WebException

Note that it always ends with an Exception suffix.

Read-only static Fields

Pascal

RedValue

Interface

Pascal

IDisposable

Always start with the I prefix.

Set

Pascal

CustomerCollection always ends with Collection

Method

Pascal

ToString

Namespace

Pascal

System. Drawing

Parameters

Camel

TypeName

Attribute

Pascal

BackColor

Protected instance Field

Camel

RedValue

Note that it is rarely used. The property is better than the protected instance field.

Public instance Field

Pascal

RedValue

Note that it is rarely used. The property is better than the public instance field.

 

Related to variable naming

Type

Prefix

Example

Array

Arr

ArrShoppingList

Boolean

Bln

BlnIsPostBack

Byte

Byt

BytPixelValue

Char

Chr

ChrDelimiter

DateTime

Dtm

DtmStartDate

Decimal

Dec

DecAverageHeight

Double

Dbl

DblSizeofUniverse

Integer

Int

IntRowCounter

Long

Lng

LngBillGatesIncome

Object

Obj

ObjReturnValue

Short

Shr

ShrAverage

Single

Sng

SngMaximum

String

Str

StrFirstName

 

Related to page controls

Data Type

Abbreviated Data Type

Standard naming example

Label

Lbl

LblMessage

LinkLabel

Llbl

LlblToday

Button

Btn

BtnSave

TextBox

Txt

TxtName

MainMenu

Mmnu

MmnuFile

CheckBox

Chk

ChkStock

RadioButton

Rbtn

RbtnSelected

GroupBox

Gbx

GbxMain

PictureBox

Pic

PicImage

Panel

Pnl

PnlBody

DataGrid

Dgrd

DgrdView

ListBox

Lst

LstProducts

CheckedListBox

Clst

ClstChecked

ComboBox

Cbo

CboMenu

ListView

Lvw

LvwBrowser

TreeView

Tvw

TvwType

TabControl

Tctl

TctlSelected

DateTimePicker

Dtp

DtpStartDate

HscrollBar

Hsb

HsbImage

VscrollBar

Vsb

VsbImage

Timer

Tmr

TmrCount

ImageList

Ilst

IlstImage

ToolBar

Tlb

TlbManage

StatusBar

Stb

StbFootPrint

OpenFileDialog

Odlg

OdlgFile

SaveFileDialog

Sdlg

SdlgSave

FoldBrowserDialog

Fbdlg

FgdlgBrowser

FontDialog

Fdlg

FdlgFoot

ColorDialog

Cdlg

CdlgColor

PrintDialog

Pdlg

Pdluplint

 

 

3. Three annotations

// A comment

 

/* A comment */

 

/// <Summary>

/// Comments

/// </Summary>

 

4. C # Type

In C #, there are two types: reference type and value type.

The following reference types are available: Class, interface, array, and delegate.

Value types include: Basic numeric types (bool, char, sbyte, short, int, long, byte, ushort, uint, ulong, float, double, decimal), enumeration type, struct

 

5. Value Type and reference type

6. value range of Value Type

 

 

7. Conversion between value types

 

8. struct

 

9. Class

(In C #, the Object Class is the base Class of all classes) the following common methods are defined in the Object: Class Object {Public virtual bool Equals (object o ){...} Public virtual string ToString (){...} Public virtual int GetHashCode (){...}...}

10. Differences between classes and struct

  Class:

1. Reference Type (objects are allocated to the stack)

2. Support inheritance

3. interfaces can be implemented

4. Ability to declare Constructors

5. You can have destructor

  Struct:

1. Value Type (the object is allocated to the stack)

2. No inheritance

3. interfaces can be implemented

4. Do not declare Constructors

5. No destructor

 

11. C # Boxing and Unboxing

  1. Boxing occurs when the value type is converted to the reference type

2. unpacking occurs when the reference type is converted to the value type

Value types include

Original Type (Sbyte, Byte, Short, Ushort, Int, Uint, Long, Ulong, Char, Float, Double, Bool, Decimal)

Enumeration (enum)

Structure (struct ).

Reference types include

Class array interface delegate string, etc.

 

Object obj = 1;

This line of statements assigns the integer constant 1 to the object type variable obj; constant 1 is the value type, the value type is to be placed on the stack, and the object is the reference type, which needs to be placed on the stack; to put the value type on the stack, You need to perform a packing operation.

Object objValue = 4;

Int value = (int) objValue;

The above two lines of code will perform a packing operation to pack integer constant 4 into the objValue of the reference type object variable, and then perform another unpacking operation, store the reference variable objValue stored on the stack to the value of the partial integer value type variable.

Packing operations may cause data to be copied on the heap and stack, and frequent packing operations may cause performance loss. In contrast, the unpacking process is still relatively small in terms of performance loss.

 

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.