隱含參考轉換 是編譯器在靜態型別系統層面判定安全、無需執行期檢查的參考型別轉換。核心原則:來源型別的執行期物件一定能作為目標型別使用。
object:根型別通吃。Derived d = new Derived(); Base b = d;IList<int> list = new List<int>();IEnumerable<int> e = list;(IList<T> : IEnumerable<T>)Derived[] → Base[],條件:
System.ArraySystem.DelegateSystem.ICloneablenull → 任意參考型別
// ❌ 編譯錯誤:元素為實值型別,無協變
float[] fa = new float[10];
int[] ia = new int[10];
fa = ia; // CS0029
// ✅ 正確:元素為參考型別,支援協變
class Base {}
class Derived : Base {}
Base[] ba = new Derived[10]; // 隱含參考轉換
float[] → System.Single[]
double[] → System.Double[]
int[] → System.Int32[]
string[] → System.String[]
這印證了 C# 基本型別對應的 CLI 型別名稱(int = System.Int32)。