程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#復習③,

C#復習③,

編輯:C#入門知識

C#復習③,


C#復習③

2016年6月16日

11:13

Main Declaration & Statement 聲明和語句

1.一個程序包含的聲明空間有哪些?

Namespace : declarations of classes , interfaces, structs, enums, delegates

命名空間:聲明類、接口、結構體、枚舉、委托

Class & interface & struct:declarations of fields, methods…

類 & 接口 & 結構體:聲明字段、方法等

enumeration: declarations of enumeration constants

枚舉: 聲明枚舉常量

Method block:declarations of local variables

方法塊:聲明局部變量

2.規則:

域規則:

No name may be declared more than once in the same declaration space 同一個聲明空間內不能存在相同的命名。

However, it may be redeclared in an inner declaration space (except in a nested statement block)

但是,相同的命名可以在內部嵌套進行多次的聲明

可見性規則:

Names declared in a method are visible from their declaration until the end of the method. 一個在方法內聲明的命名,其生命期限從從聲明開始到該方法的結束為期生命空間。

If a name is redeclared in an inner declaration space, it hides the same name from the outer declaration space. 如果在內部嵌套的聲明空間中存在一個與外部空間相同的命名,則在內部空間該命名會將外部的命名覆蓋掉。

In general, no name is visible outside its declaration space.通常情況下,沒有命名能夠在其聲明空間之外可見。

3.Namespace 命名空間

可以嵌套其他的命名空間;內部可以包含多個枚舉、多個類、多個接口;

存在嵌套命名空間時,內部的命名空間需要通過外部命名空間加上點“.”運算符進行調取。

4.Classes & Interface & Structs & Enumeration 類、接口、結構體和枚舉

5. Statement Blocks 聲明塊

可以包括多個不同的平行作用域以及嵌套作用域。

6.Declaration of Local Variables 聲明局部變量

局部變量對全局變量的覆蓋,以及不同變量的存在空間

7.Simple Statement 簡單語句

空語句 ;

賦值語句 sum + = x ;

方法調用:string []parts = s.Split(',');

8.if Statement if語句

9.switch Statement switch 語句

能夠作為跳轉表達式的類型:integer type,char ,enum

switch  case語句適用於從一組互斥的分支中選擇一個執行分支。

值得注意的就是case的值必須是常量表達式不允許是變量。

在C#中,switch語句的一個有趣的地方是case子句的排放更靈活,甚至可以將default子句放在最前面(因為任何兩個case都不能相同)。

10.Loops 循環語句

while循環語句

do while循環

for循環

11.foreach Statement foreach 語句

12.Jump 跳轉語句

13.return Statement 返回語句

14.output to the Console 輸出到控制台

15.Formatting Codes for numbers 數字格式化

16.Formatted Output to a File格式輸出到文件

17.Keyboard Input鍵盤輸入

18.Input from a File從文件讀取

19.Reading Command-line Parameters 讀取命令行參數

clip_image019

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved