Home [C# 筆記] 里氏轉換、集合、讀寫數據 -Review4
Post
Cancel

[C# 筆記] 里氏轉換、集合、讀寫數據 -Review4

里氏轉換

  • 子類可以賦值給父類
  • 如果父類中裝的是子類物件,那麼可以將這個父類強制轉換為子類物件

集合:陣列類型任意

ArrayList

1
2
3
4
5
6
7
8
9
Add
AddRange
Remove
RemoveAt
Insert
InsertRange
Clear
Reverse
Sort

Hashtable

根據key去找值
ht[key]=值;

Path

操作路徑的

1
2
3
4
5
File
Create
Delete
Move
Copy

讀寫數據

  • ReadAllBytes()
    字串陣列 -> 字串
    Encoding.Default.GetString(字串陣列)

  • WriteAllBytes()
    字串 -> 字串陣列
    Enconding.Default.GetBytes(字串)

ReadAllBytes()

1
2
3
byte[] buffer = File.ReadAllBytes(@"C:\Users\rivalin\Desktop\new.txt");
string s = Encoding.Default.GetString(buffer); //將byte[]陣列按照指定的編碼格式解碼成字串  
Console.WriteLine(s);

WriteAllBytes()

1
2
3
4
string s = "今天天氣真好啊";
byte[] buffer = Encoding.Default.GetBytes(s); //需要將寫入的字串轉成byte[]陣列
File.WriteAllBytes(@"C:\Users\rivalin\Desktop\lala.txt", buffer);
Console.WriteLine("done");
This post is licensed under CC BY 4.0 by the author.