当前位置:网站首页>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边栏推荐
- Pl/sql basic syntax
- Technology cloud report: how many hurdles does the computing power network need to cross?
- How to create a thread
- Implementation technology of recovery
- What about data leakage? " Watson k'7 moves to eliminate security threats
- U盘的文件无法删除文件怎么办?Win11无法删除U盘文件解决教程
- Oracle hint understanding
- Promql demo service
- Blocking protocol for concurrency control
- A trip to Suzhou during the Dragon Boat Festival holiday
猜你喜欢
Search: Future Vision (moving sword)
Unique occurrence times of leetcode simple questions
Leetcode simple question: check whether each row and column contain all integers
Cobaltstrike builds an intranet tunnel
Wonderful review of the digital Expo | highlight scientific research strength, and Zhongchuang computing power won the digital influence enterprise award
Granularity of blocking of concurrency control
What changes has Web3 brought to the Internet?
IIC bus realizes client device
Postman核心功能解析-参数化和测试报告
如何快速体验OneOS
随机推荐
Form artifact
数博会精彩回顾 | 彰显科研实力,中创算力荣获数字化影响力企业奖
Metaverse Ape猿界应邀出席2022·粤港澳大湾区元宇宙和web3.0主题峰会,分享猿界在Web3时代从技术到应用的文明进化历程
Sparse array [matrix]
科技云报道:算力网络,还需跨越几道坎?
Decorator learning 01
QT creator 7 beta release
What if the files on the USB flash disk cannot be deleted? Win11 unable to delete U disk file solution tutorial
Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
509. Fibonacci Number. Sol
Draw a red lantern with MATLAB
Navigation day answer applet: preliminary competition of navigation knowledge competition
"Chris Richardson microservices series" uses API gateway to build microservices
點到直線的距離直線的交點及夾角
Go语言学习教程(十五)
Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
Index optimization of performance tuning methodology
Analysis of the problem that the cookie value in PHP contains a plus sign (+) and becomes a space
Overview of database recovery
Leetcode simple question ring and rod