<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 1、DataSet xx :離線資料庫 # 2、DataReader:連線資料庫 # 3、事件托管:(object sender, EventArgs e) 前面的object用來傳遞事件的發生者,后面的EventArgs用來傳遞事件的細節 https://zhidao.baidu.com/question/107479680.html?qbl=relate_question_3 # 4、命名規則 ``` namespace M1 { public class C{} } ``` 可以表達成M1.C # 5、新建project時候一般選擇console solution # 6、常量和變量 常量: 編譯時常量const 需要一開始就賦值,如果是運行時常量readonly,則可以在運行時候在g構造函數中再賦值。 ![](https://box.kancloud.cn/272b2ea53d818aa15d5c4df13e1f1fc9_693x277.png) ``` using System public class Program { const abc = 900; //設定名叫abc的常量,值是900。常量類型一般用const表示 static void Main(string[] agrs) { Console.WriteLine("常量abc的值是:{0}", abc); //這里{0}必須寫,否則出錯 } } ``` ![](https://ws4.sinaimg.cn/large/006tNc79gy1fojsyrjd4jj30jo08v0tz.jpg) ## 變量類型 ![](https://ws3.sinaimg.cn/large/006tKfTcgy1fr387u21m8j31hc0u0mzd.jpg) ## 變量的作用域 ![](https://ws2.sinaimg.cn/large/006tKfTcly1fr3kx174cwj31kw0w0kjl.jpg) 類體 => 成員變量 - 實例變量 `string x = "hello"; ` 實例變量只屬于某個對象實例,所以調用時候需要先創建實例。 - 靜態變量 ` static string x = "hello"; ` 靜態變量是屬于一整個class 類的 兩者的區別:如果輸入了`static ` 變量以后,則我們可以在該類的 static void main() 中直接調用 > 局部變量如果在外部用?沒其他辦法,最簡單的就是直接加一個static ``` class Program() { static string x = "hello"; static void Main() { Console.WriteLine(x); } } ``` 如果是用了實例變量,那么我們必須先用 Program 創建對象,否則會提示: CS0120 C# An object reference is required for the non-static field, method, or property 對象引用于非靜態的字段,方法或屬性“Program.x”是必須的 ![](https://ws3.sinaimg.cn/large/006tKfTcly1fr3klr0lhaj30il0du0uf.jpg) 正確做法如下: ``` class Program() { string x = "hello"; static void Main() { Program p = new Program(); Console.WriteLine(p.x); //注意這里括號里面寫的是對象名p,而不再是變量名 } } ``` ![](https://ws1.sinaimg.cn/large/006tKfTcly1fr3krg8e52j30is0b8dhc.jpg) ## 轉義字符 ![](https://ws2.sinaimg.cn/large/006tKfTcgy1fr387uu9goj31hc0u0gp3.jpg) ![](https://ws3.sinaimg.cn/large/006tKfTcgy1fr3878tn7tj31hc0u0diy.jpg) # 常量——一般常量名都大寫 ## 編譯時常量,用const表示 需要初始化值,如`const int PI=3.14;` 一開始就定義,與順序無關。 ## 運行時常量,用readonly 表示 可定義時直接賦值,也可以借助Program()來執行。不能定義在具體對方法中,只能定義在類里面,或者是在構造函數Program里面初始化,其余不行。是一行運行的,所以有順序。 ``` class Program() { readonly int Price; Program() { Price = 365; } static void Main() { ……; } } ``` > 注意,如果是readonly時,那么代碼是一行行讀取的。 > 這時候如果先寫了price3=price4*\2,再寫Price4 = 55,那么price3的值只能是0。 ![](https://ws2.sinaimg.cn/large/006tNc79ly1fr7sgtp4vgj30a304yjrr.jpg) ![](https://ws4.sinaimg.cn/large/006tNc79ly1fr7sdhizemj30j50cg0vh.jpg) # 運算符 ## 賦值運算 用=表示。 如k=5 ## 關系運算符 `==, !=, <, >, <=, >= ` 等。但關系運算符不能連用。比如 ` console.writeline(a<b<c); ` 提示輸出錯誤。因為系統是從左到右判斷。先執行了a<b以后得到到是bool類型的值,再執行bool<c的判斷,就會發生錯誤。 這時候可以用a<b && b<c; 即可 ## 位運算符 作用的對象是二進制數。 比如:&、|、^、~ - 位與運算`&`,兩個數都是1,才返回1。如`1 & 0`,返回0。 - 位或運算`|`,只要有一個是1,就返回1。如`1 | 0`,返回1。 - 位異或運算 `^`,兩個都是0,或者兩個都是1,則返回0,否則返回1。如`11 ^ 10`,返回01。 - 位取反運算`~`,把0變成1,把1變成0即可。 ![](https://ws4.sinaimg.cn/large/006tNc79ly1fr8b44qddhj30j00b8wgg.jpg) 上述例子中用到了convert.toint32 ## 移位運算 `<<` 左移位 數字轉換成二進制以后,最左邊到數(高位數)被移出去舍棄,右邊的數補充0。也就是等于原來的數??2的n次冪。比如移2位就是原來數??22。 `>>` 右移位 左邊被填充進來。需要注意的是,如果是負數,那么填充的是1,如果是正數,那么填充的是0,相當于÷2的 n 次冪。 ![](https://ws2.sinaimg.cn/large/006tKfTcly1fr8bgto0xtj30fy0913zg.jpg) ## 條件運算 語句為 xxx?xxx:xxx。條件運算不能直接作為一句c#語句,而要定義一個變量來接收它的值。例如下面的result 但一般用sting result 寫 ``` static void Main() { int num = 50; string result = num>40?"is true":"is false"; console.writeline(result); console.readline(); } ``` 嵌套使用: **從右向左執行** 例如 ``` static void Main() { int x = 5, y = 6, a = 1, b = 2; int z = 0; z = x > y ? x : a > b ? a : b; Console.WriteLine(z); Console.ReadLine(); } ``` ![](https://ws4.sinaimg.cn/large/006tKfTcly1fr8nggia72j30hs09hjsl.jpg) # 7、 ``` using System; namespace MyApp { class MyApp { static void Main(string[] agrs) { int a1 = 25; int b1 = 30; Console.WriteLine("{0} + {1} = {2}", a1, b1, a1 + b1); //這里{0}, {1}, 是因為main中定義了(string[] agrs), 是個數組類型,所以默認 a1存放到數組的第一個 } } } ``` # 8、if null 創新和異常 `throw`字段 ``` if ( value == "") { throw new ArgumentException() } ``` # 9、new new:關鍵字實例化 比如 struct Book { } # 10、字符轉換 ## 隱式類型 默認一些類型可以互相轉換,比如char類型可以轉換成double int float類型。但bool類型只有true false兩種結果,所以不能跟數值類型互相轉換。 ## 顯式類型(強制類型轉換) 1. 直接加(類型名) 把高精度轉換為低精度的時候需要顯式類型轉換。比如直接加一個(int),注意這里有括號。 ``` int b = (int)10.2 ``` ![](https://box.kancloud.cn/d26ad2913c23b661b5881f6b8961d156_676x543.png) 2. 或者用convert.to轉換,這個類是.net自帶的類。應用最多!如: ``` double a = 10.5; int c = convert.toint32(a); ``` 3. 用類型名.Parse(表達式),但只能針對數值類型。所以暫不用 ``` double a = 10.5; int c = Int.Parse(a.ToString()); ``` # 11、運算符優先級和結合性 ![](https://box.kancloud.cn/4c86b5244d7d891287fd32cd48984f5d_1001x555.png) 表格中從上到下變低。 ![](https://box.kancloud.cn/aa25b5129ab276e263a5e10bfee6c8a0_979x459.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看