当前位置:网站首页>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边栏推荐
- Basic grammar of interview (Part 1)
- Platformio create libopencm3 + FreeRTOS project
- 90后测试员:“入职阿里,这一次,我决定不在跳槽了”
- How to develop and introduce applet plug-ins
- Nacos 的安装与服务的注册
- Implementation technology of recovery
- 航海日答题小程序之航海知识竞赛初赛
- Assign the output of a command to a variable [repeat] - assigning the output of a command to a variable [duplicate]
- Interprocess communication in the "Chris Richardson microservice series" microservice architecture
- Leetcode simple question ring and rod
猜你喜欢

boundary IoU 的计算方式

Pl/sql basic syntax

Distance from point to line intersection and included angle of line

Type of fault

Nacos 的安装与服务的注册

Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法

Kubernetes Administrator certification (CKA) exam notes (IV)

Stored procedures and stored functions
![[error record] groovy function parameter dynamic type error (guess: groovy.lang.missingmethodexception: no signature of method)](/img/3e/34b45cd14f0302bb381efd244bc68f.jpg)
[error record] groovy function parameter dynamic type error (guess: groovy.lang.missingmethodexception: no signature of method)

Wonderful review of the digital Expo | highlight scientific research strength, and Zhongchuang computing power won the digital influence enterprise award
随机推荐
Advantages and disadvantages of the "Chris Richardson microservice series" microservice architecture
Leetcode simple question: check whether each row and column contain all integers
Learning of mall permission module
The new content of the text component can be added through the tag_ Config set foreground and background colors
opencv 判断点在多边形内外
微服务链路风险分析
1.3 years of work experience, double non naked resignation agency face-to-face experience [already employed]
Database tuning solution
Metaverse Ape上线倒计时,推荐活动火爆进行
C language knowledge points link
Matlab draws a cute fat doll
Metaverse Ape获Negentropy Capital种子轮融资350万美元
Bitbucket installation configuration
Business learning of mall commodity module
Oracle hint understanding
Metaverse Ape猿界应邀出席2022·粤港澳大湾区元宇宙和web3.0主题峰会,分享猿界在Web3时代从技术到应用的文明进化历程
Overview of concurrency control
New 3D particle function in QT 6.3
How to quickly experience oneos
Business learning of mall order module