C#英語筆記Day 75

1.詞匯

  • Array covariance 數(shù)組協(xié)變
  • type safety 類型安全
  • at compile time 編譯時
  • at execution time 執(zhí)行時

2.例句

  • code listing 代碼清單
string[] strings = new string[5];
object[] objects = strings;
objects[0] = new Button();
  • If you run listing above, you’ll see that an ArrayTypeMismatchException is thrown, This is because the conversion from string[] to object[] returns the original reference—both strings and objects refer to the same array.

    如果運(yùn)行上面的清單,您會看到拋出了一個ArrayTypeMismatchException類型的異常,這是因?yàn)閺膕tring[]到object[]的轉(zhuǎn)換返回了原始引用,字符串和對象都引用同一個數(shù)組。

  • The array itself knows it’s a string array and will reject attempts to store references to nonstrings.

    數(shù)組本身知道它是一個字符串?dāng)?shù)組,并將拒絕存儲對非字符串的引用的嘗試。

  • Array covariance is occasionally useful, but it comes at the cost of implementing some of the type safety at execution time instead of compile time.

    數(shù)組協(xié)變有時會派上用場,但它的代價是在執(zhí)行時而不是在編譯時實(shí)現(xiàn)類型安全性。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容