C#英语笔记Day 75

1.词汇

  • Array covariance 数组协变
  • type safety 类型安全
  • at compile time 编译时
  • at execution time 执行时

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.

    如果运行上面的清单,您会看到抛出了一个ArrayTypeMismatchException类型的异常,这是因为从string[]到object[]的转换返回了原始引用,字符串和对象都引用同一个数组。

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

    数组本身知道它是一个字符串数组,并将拒绝存储对非字符串的引用的尝试。

  • 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.

    数组协变有时会派上用场,但它的代价是在执行时而不是在编译时实现类型安全性。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容