1
Outline 數 料 數 數 列 亂數 練
數 數 數 來 數 數 來 數 料 利 料 來
數 A-Z a-z _ () 不 數 0-9 數 不 數 SCHOOL School school 數 讀 school_name schoolname 易 不 C# my name 7_eleven B&Q new
C# (1) public protected private params override out operator object null new namespace long lock is internal interface int in implicit if goto foreach for float fixed finally false extern explicit event enum else double do delegate default decimal continue const class checked char catch case byte break bool base as abstract
C# (2) readonly ref return sbyte sealed short sizeof stackalloc static string struct switch this throw true try typeof uint ulong unchecked unsafe ushort using virtual volatile void while
Outline 數 料 數 數 列 亂數 練
料 數 數 數 林 列 參 串 列 類
數 sbyte byte short ushort int uint long ulong 8 8 16 16 32 32 64 64 數 -128 ~ 127 0 ~ 255-32768 ~ 32767 0 ~ 65535-2147483648 ~ 2147483647 0 ~ 4294967295-9223372036854775808 ~9223372036854775807 0 ~ 18446744073709551615
數 數 來 數 數 精 度 數 float 32 7 1.5 10-45 ~ 3.4 10 38 double 64 15~16 5.0 10-324 ~ 1.7 10 308 float 數 數 f decimal 理 數 28 數 金 林 bool 林 true false
串 char 來 料 來 例 'A' 'a' '1' '2' 串 string 來 串 串 料 串 來 例 "my name is ives!!"
Outline 數 料 數 數 列 亂數 練
數 數 了 留 來 料 料 數 ; int telnum; int telnum = 321; string myname; string myname = ives ; string myname = ; int i = 16, j, k;
例 sample1-a1 行列 "XXX!!" 行列 " XXX!! " 說 static void Main(string[] args) { Console.Write(""); } string username = Console.ReadLine(); Console.WriteLine(userName + "!!"); Console.WriteLine(" " + username + "!!" ); Console.ReadLine();
練 sample1-b1 行 行 行 列 "XXX!! 行 列 " XXX X!! " 念 串 數
Outline 數 料 數 數 列 亂數 練
數 (implicity) 數 數 例 int a = 321; long b = a; (explicity) 料 例 long a = 123; int b = (int) a;
串數 數 串 利 ToString() 來 例 int a = 321; string b = a.tostring(); 串 數 利 數 Parse() 來 例 string b = "321"; int a = int.parse(b);
例 sample1-a2 (1) 串數 料 說 說 // 料 float a = 3.14f; double b = 3.9; Console.Write(" : "); Console.Write("a = " + a); Console.WriteLine(", b = "+ b); Console.Write(" : "); Console.Write("a = " + (int)a); Console.WriteLine(", b = " + (int)b);
例 sample1-a2 (2) 說 // 串數 Console.Write(" 數 :"); string c = Console.ReadLine(); Console.WriteLine(c + " 1 " + (int.parse(c) + 1).ToString()); Console.ReadLine();
練 sample1-b2 練 數 數 數 數 列 來 念 讀 料 數 理 串
Outline 數 料 數 數 列 亂數 練
行 數 + - * / 例 i = j + k; i = j - k; i = j * k; i = j / k; % 串 串 int i = 16, j, k; j = i / 3; // j 5 k = i % 3; // k 1 i = j % k;
練 sample1-b3 列 行 ( 數 ) 列 念 Console.ReadLine() 讀 來 料 串 數
(1) 串 數 (true) (false) ==!= > < >= <= 不 例 i == j i!= j i > j i < j i >= j i <= j
(2) 4 > 3 // true 'a' > 'b' // false Unicode 來 a Unicode 97 b Unicode 98 b a
例 sample1-a3 數 列 數 說 // 數 Console.Write(" 數 :"); int i = int.parse(console.readline()); Console.Write(" 數 :"); int j = int.parse(console.readline()); // 列 Console.WriteLine(i + " == " + j + " " + (i==j)); Console.WriteLine(i + "!= " + j + " " + (i!=j)); Console.WriteLine(i + " > " + j + " " + (i>j)); Console.WriteLine(i + " < " + j + " " + (i<j)); Console.WriteLine(i + " >= " + j + " " + (i>=j)); Console.WriteLine(i + " <= " + j + " " + (i<=j));
練 sample1-b4 數 數 5 5 列 true 列 false 念 利 > <=
來 例 && i && j i j i j 若 i j!!i 若 i 若 i (4>3) && ('a'=='b') //(true) && (false) false (4>3) ('a'=='b') //(true) (false) true! (4>3) //!(true) false
(=) 來 來 例 來 = i = 5 i = 5 += i += 5 i = i + 5 -= i -= 5 i = i - 5 *= i *= 5 i = i * 5 /= i /= 5 i = i / 5 %= i %= 5 i = i % 5
練 sample1-b5 ( 數 ) 列 念 利
來 數 數 數 ++ 數 例 i++ ++i -- 數 int a = 5, b = 5; int c = a++; //c 5 int d = ++b; //d 6 i-- --i
例 sample1-a4 說 說 int i=10, j=0, x=10, y=0; j += ++i; Console.WriteLine("i ="+ i +", j = " + j); y += x++; Console.WriteLine("x =" + x +", y = " + y); Console.WriteLine("x =" + x++); Console.WriteLine("x =" + x);
a + b + c 行 a + b c a + b * c 行 b * c a (a + b) * c 行 a + b c a = b = c c b b a
Outline 數 料 數 數 列 亂數 練
數 數 數 來 料 不 數 數 const double pi = 3.1415926;
練 sample1-b6 ( 數 ) 列 念 數 pi = 3.1415926 * * pi
Outline 數 料 數 數 列 亂數 練
列 列 來 ( 數 ) 列 int byte sbyte short ushort uint long ulong 列, 列 不 enum language:long { English = 0, Chinese = 1 }
例 sample1-a5 列 錄 說 enum studentid:int { alice = 12, bob = 24 } static void Main(string[] args) { Console.WriteLine(studentID.alice + " : " + (int)studentid.alice); Console.WriteLine(studentID.bob + " : " + (int)studentid.bob); Console.ReadLine(); }
練 sample1-b7 列 念 利 列 數 錄 來 Sun = 1, Mon = 2, Tue = 3, Wed = 4, Thi = 5, Fri = 6, Sat = 7
Outline 數 料 數 數 列 亂數 練
料 來 不 不 struct student { public int id; public string name; }
例 sample1-a6 利 struct 立 student 料 說 struct student { public int id; public string name; } static void Main(string[] args) { student ives; ives.id = 27; ives.name = "ives"; } Console.WriteLine(": " + ives.name + "\n" + ": " + ives.id );
練 sample1-b8 利 錄 料 列 行 年 列 料 念 利 struct 立 name age tel 料欄
Outline 數 料 數 數 列 亂數 練
亂數 亂數 來 數 亂數 Random 數 = new Random(); 亂數 數.Next(, ) 亂數
例 sample1-a7 列 1 ~ 9 亂數 說 // 亂數 Random rnd = new Random(); // 亂數 Console.WriteLine(rnd.Next(1,10)); Console.WriteLine(rnd.Next(1,10)); Console.WriteLine(rnd.Next(1,10));
練 sample1-b9 亂數 1 ~ 3 數 數 列 ture false 念 利 Random Next
Outline 數 料 數 數 列 亂數 練
練 hw2 (1) Bob Alice 利 數 列 Bob Alice 了 利 struct 錄 Bob Alice 列 Bob Alice 列 Bob 句
練 hw2 (2) 行