## 可索引集合
```
List<int> numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
List salmons = ["chinook", "coho", "pink", "sockeye"];
salmons.Remove("coho");
salmons.Add("coho");
```
由[List](https://learn.microsoft.com/zh-cn/dotnet/api/system.collections.generic.list-1)使用的`Galaxy`類在代碼中定義
```
private static void IterateThroughList()
{
var theGalaxies = new List<Galaxy>
{
new (){ Name="Tadpole", MegaLightYears=400},
new (){ Name="Pinwheel", MegaLightYears=25},
new (){ Name="Milky Way", MegaLightYears=0},
new (){ Name="Andromeda", MegaLightYears=3}
};
foreach (Galaxy theGalaxy in theGalaxies)
{
Console.WriteLine(theGalaxy.Name + " " + theGalaxy.MegaLightYears);
}
// Output:
// Tadpole 400
// Pinwheel 25
// Milky Way 0
// Andromeda 3
}
public class Galaxy
{
public string Name { get; set; }
public int MegaLightYears { get; set; }
}
```
## 鍵/值對集合
[Dictionary](https://learn.microsoft.com/zh-cn/dotnet/api/system.collections.generic.dictionary-2)類 字典集合
創建`Dictionary`集合并通過使用`foreach`語句循環訪問字典
```
private static void IterateThruDictionary()
{
Dictionary<string, Element> elements = BuildDictionary();
foreach (KeyValuePair<string, Element> kvp in elements)
{
Element theElement = kvp.Value;
Console.WriteLine("key: " + kvp.Key);
Console.WriteLine("values: " + theElement.Symbol + " " +
theElement.Name + " " + theElement.AtomicNumber);
}
}
public class Element
{
public required string Symbol { get; init; }
public required string Name { get; init; }
public required int AtomicNumber { get; init; }
}
private static Dictionary<string, Element> BuildDictionary() =>
new ()
{
{"K",
new (){ Symbol="K", Name="Potassium", AtomicNumber=19}},
{"Ca",
new (){ Symbol="Ca", Name="Calcium", AtomicNumber=20}},
{"Sc",
new (){ Symbol="Sc", Name="Scandium", AtomicNumber=21}},
{"Ti",
new (){ Symbol="Ti", Name="Titanium", AtomicNumber=22}}
};
```
- Visual Studio 2022安裝到非C盤
- .net平臺區別
- 常用單詞
- 關鍵字
- 操作符(運算符)
- 標識符(命名規范)
- 開始
- 變量
- 常量
- 數據類型
- 值類型
- 變量數據類型
- 枚舉類型enum(常量集合)
- 結構類型struct(結構體)
- 元組類型
- 可null類型(T?)
- 引用類型
- 數組(array)
- 集合(List)
- 內置引用類型
- object
- string
- Dynamic(動態類型)
- delegate委托(代理)類型
- 自定義引用類型
- 接口(interface)
- 類class
- record(定義一個引用類型)
- 指針類型(僅用于非安全代碼)
- get和set訪問器
- delegate委托
- delegate實現發布訂閱與事件
- 類型轉換
- 合并操作符??
- 類相關
- Partial 部分類
- 類定義以及訪問修飾符(封裝)
- abstract抽象類與sealed密封類
- virtual虛方法
- 接口interface
- C# 預處理器指令
- C#技術棧
- 判斷(流程控制)與三元運算
- if
- switch
- 三元運算
- 循環
- while 循環
- for循環
- foreach循環
- do...while 循環
- 文件操作
- 其他
- 多開