C# 文法練習(5): 語句

if (bool) { } else { }switch (v) { case v1: ... break; case v2: ... break; ... default: ... break; }do { } while (bool);while (bool) { }for (int i; i C# 的 switch 語句支援字串, 但好像只能用 const string 類型的變數.using System;class MyClass{ static void Main() {

C# 文法練習(6): 枚舉

顯示枚舉、枚舉值、枚舉名:using System;class MyClass{ enum MyEnum { AA, BB, CC }; /* 類型定義不能在函數體內 */ static void Main() { MyEnum e = MyEnum.CC; Console.WriteLine(e); // CC Console.WriteLine((byte)e); //

C# 文法練習(7): 數組

字串數組:using System;class MyClass{ static void Main() { string[] arr = new string[3] { "aa", "bb", "cc" }; foreach (string s in arr) Console.WriteLine(s); // aa/bb/cc Console.ReadKey(); }}整數數組:using System;class MyClass{

C# 文法練習(8): 函數

無參、無傳回值的函數:using System;class MyClass{ static void Show() { Console.WriteLine("function"); } static void Main() { Show(); //function Console.ReadKey(); }}參數:using System;class MyClass{ static void

C# 文法練習(9): 類[一] – 訪問限制、方法、欄位、屬性

所有類預設繼承於 System.Object(或叫 Object):using System;class MyClass1{}class MyClass2 : Object{}class MyClass3 : System.Object{}class Program{ static void Main() { MyClass1 obj1 = new MyClass1(); MyClass2 obj2 = new MyClass2();

學點 C 語言(33): 函數 – 傳值與傳址、形參與實參

1. 傳值參數(非指標參數):#include <stdio.h>int inc(int x);int main(void){ int num = 1; printf("%d\n", inc(num)); /* 2 */ printf("%d\n", num); /* 1; num 並沒有改變, 用作函數參數時只是複製過去 */ getchar(); return 0;}int inc(int x) { x++;

學點 C 語言(34): 函數 – 關於變數(auto、static、register、extern、volatile、restrict)

1. 局部變數:局部變數也叫自動變數, 它聲明在函數開始, 生存於棧, 它的生命隨著函數返回而結束.#include <stdio.h>int main(void){ auto int i = 9; /* 聲明局部變數的關鍵字是 auto; 因可以省略, 幾乎沒人使用 */ printf("%d\n", i); getchar(); return 0;}2. 全域變數:全域變數聲明在函數體外, 一般應在函數前; 每個函數都可以使用它,

學點 C 語言(36): 函數 – 數組參數

數組參數屬於指標參數.指標參數即時傳址參數(或叫引用參數), 如果想在函數中修改參數的值, 這是唯一的途徑.如果把數組當作參數, 不管你願意與否, 它就是指標, 指向第一個值的指標.1. 數組參數就是指向第一個元素的指標:#include <stdio.h>void getArr(int p[], int si);int main(void){ int ns[] = {1,2,3,4,5}; getArr(ns, sizeof(ns)/sizeof(ns[0]));

學點 C 語言(40): 函數 – 多參函數

像 printf 這種多參函數, 是借用 stdarg.h 中的宏實現的.va_list : 用於定義遍曆參數列表的指標;va_start : 讓指標指向第一個參數;va_arg : 擷取下一個參數, 並向後移動一個位置;va_end : 釋放指標, 完成遍曆.1. 整數求和:本例實現了對系列整數求和, 要求至少要有三個參數, 並且最後一個必須是 0.最後的 0 用於識別列表結束.#include <stdio.h>#include <stdarg.h>int

學點 C 語言(37): 函數 – 常量(const)參數

非指標參數(也就是傳值參數)不會被修改原始值, const 對它是沒有意義的.const 只用於指標.1. 第一種用法: const 類型 *變數:這種用法將限制修改指標指向的值.#include <stdio.h>int fun(const int *p) { *p += 1; /* 只有去掉 const 這句才可以執行 */ return *p;}int main(void){ int num = 3; printf("%d\n", fun(&

學點 C 語言(38): 函數 – 函數指標

先複習函數的定義與函數的聲明://這是一個求和函數的定義:int add(int x, int y){ return(x + y);}//可以這樣聲明:int add(int x, int y);//也可以這樣聲明:int add(int, int);定義一個函數指標聲明一個函數差不多, 用 (* ) 包括函數即可://像這樣:int (*pfun)(int, int);//或這樣:int (*pfun)(int x, int y);//也可以:typedef int

C# 文法練習(1): 基礎資料型別 (Elementary Data Type)

本例:代碼:using System;class MyClass{ static void Main() { Console.WriteLine("sbyte 類型:"); sbyte sbyteVar = (sbyte.MaxValue + sbyte.MinValue) / 2; Console.WriteLine("{0}、{1}、{2}\n", sbyte.MinValue, sbyteVar, sbyte.MaxValue);

C# 文法練習(10): 類[二] – 繼承、覆蓋、多態、隱藏

繼承:using System;class Parent{ public void Msg() { Console.WriteLine("Parent"); }}class Child : Parent { }class Program{ static void Main() { Parent ObjParent = new Parent(); Child ObjChild = new Child(); ObjParent.Msg();

C# 文法練習(11): 類[三] – 建構函式、解構函式、base、this

建構函式與解構函式:using System;class MyClass{ private int FNum; public int Num { get { return FNum; } } /* 建構函式沒有傳回值, 無參的建構函式是預設的 */ public MyClass() { this.FNum = 2009; } /* 可以有多個參數不同的建構函式 */ public MyClass(int x) {

硬著頭皮學點 C++(1): 前言

說實話, 有了 Delphi 真的很難喜歡 C++; 起碼對我是這樣.在我學點 C 與 C++ 的同時, 更加感到 Delphi 的優秀: 它就是 C 與 C++ 集合、與進步.但當 Delphi 過了入門關以後, 學習資料實在是太少了!很多好的技術是用 C/C++ 描述的... 因此我不得不硬著頭皮去瞭解一些.起初僅僅是為了更好地看懂那些書, 但也有意外收穫: 換個視角看 Delphi、能更好地理解 Delphi.但我不認為這是繼續深入 Delphi 的好方法, 實在是別無選擇;

C# 文法練習(12): 類[四] – 抽象類別與抽象成員、密封類與密封成員

抽象類別不能直接執行個體化:using System;abstract class MyClass{ }class Program{ static void Main() { /* 抽象類別不能直接執行個體化, 下面這樣會出錯 */ MyClass obj = new MyClass(); Console.ReadKey(); }}但抽象類別可以通過子類執行個體化:using System;abstract class

C# 文法練習(3): 運算子

基本: . () [] x++ x-- new typeof checked unchecked -> ::一元: + - ! ~ ++x --x (T)x True False & sizeof乘除: * / %加減: + -移位: >關係: = is as 相等: == !=邏輯: & ^ |條件: && ||賦值: = += -= *= /= %= &= |=

C# 文法練習(13): 類[五] – 索引器

通過索引器可以方便使用類中的數組(或集合)成員:using System;class MyClass{ private float[] fs = new float[3] { 1.1f, 2.2f, 3.3f }; /* 屬性 */ public int Length { get { return fs.Length; } set { fs = new float[value]; } } /* 索引器 */ public

C# 文法練習(4): 類型轉換

使用 Convert 類:ToBoolean -> boolToByte -> byteToChar -> charToDateTime -> DateTimeToDecimal -> decimalToDouble -> doubleToInt16 -> shortToInt32 -> intToInt64 -> longToSByte -> sbyteToSingle ->

C# 文法練習(14): 類[六] – 事件

using System;class MyClass{ private int FNum; public delegate void MyDelegate(int n); /* 委託是事件的前提 */ public event MyDelegate MyEvent; /* 用 event 關鍵字根據已有的委託聲明事件 */ /* 假如是在給 Num 賦值時觸動事件 */ public int Num { get { return

總頁數: 4314 1 .... 425 426 427 428 429 .... 4314 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.