当前位置:网站首页>Why does the C# compiler allow an explicit cast between IEnumerable< T> and TAlmostAnything?
Why does the C# compiler allow an explicit cast between IEnumerable< T> and TAlmostAnything?
2022-07-05 22:21:00 【French red wine sweet】
problem :
The following code gives you a compiler error, as you'd expect: The following code provides you with compiler errors , As you would expect :
List<Banana> aBunchOfBananas = new List<Banana>();Banana justOneBanana = (Banana)aBunchOfBananas;However, when using IEnumerable<Banana> , you merely get a runtime error. however , Use IEnumerable<Banana> , Only runtime errors will occur .
IEnumerable<Banana> aBunchOfBananas = new List<Banana>();Banana justOneBanana = (Banana)aBunchOfBananas;Why does the C# compiler allow this? Why? C# The compiler allows this ?
Solution :
Reference resources : https://stackoom.com/en/question/capE边栏推荐
- Bitbucket installation configuration
- Technology cloud report: how many hurdles does the computing power network need to cross?
- Web3为互联网带来了哪些改变?
- Unique occurrence times of leetcode simple questions
- Metaverse Ape猿界应邀出席2022·粤港澳大湾区元宇宙和web3.0主题峰会,分享猿界在Web3时代从技术到应用的文明进化历程
- 科技云报道荣膺全球云计算大会“云鼎奖”2013-2022十周年特别贡献奖
- Text组件新增内容通过tag_config设置前景色、背景色
- How to develop and introduce applet plug-ins
- Livelocks and deadlocks of concurrency control
- Pl/sql basic case
猜你喜欢

Alternating merging strings of leetcode simple questions

Index optimization of performance tuning methodology

如何快速体验OneOS

Implementation technology of recovery

Lightweight dynamic monitorable thread pool based on configuration center - dynamictp

Sentinel production environment practice (I)

装饰器学习01

A trip to Suzhou during the Dragon Boat Festival holiday

Cobaltstrike builds an intranet tunnel

Practice: fabric user certificate revocation operation process
随机推荐
Official clarification statement of Jihu company
The statistics of leetcode simple question is the public string that has appeared once
如何快速体验OneOS
Distance entre les points et les lignes
boundary IoU 的计算方式
Livelocks and deadlocks of concurrency control
Navigation day answer applet: preliminary competition of navigation knowledge competition
The real situation of programmers
Basic grammar of interview (Part 1)
Kubernetes Administrator certification (CKA) exam notes (IV)
What changes has Web3 brought to the Internet?
"Chris Richardson microservices series" uses API gateway to build microservices
CA certificate trampled pit
数博会精彩回顾 | 彰显科研实力,中创算力荣获数字化影响力企业奖
Performance monitoring of database tuning solutions
航海日答题小程序之航海知识竞赛初赛
Matlab draws a cute fat doll
GWT module may need to be (RE) compiled reduce - GWT module may need to be (RE) compiled reduce
A substring with a length of three and different characters in the leetcode simple question
Leetcode simple question: the minimum cost of buying candy at a discount