当前位置:网站首页>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边栏推荐
- Alternating merging strings of leetcode simple questions
- Distance entre les points et les lignes
- [error record] file search strategy in groovy project (src/main/groovy/script.groovy needs to be used in the main function | groovy script directly uses the relative path of code)
- Oracle is sorted by creation time. If the creation time is empty, the record is placed last
- 344. Reverse String. Sol
- Installation of VMware Workstation
- Two stage locking protocol for concurrency control
- Qtquick3d real time reflection
- Damn, window in ie open()
- 如何创建线程
猜你喜欢

Database recovery strategy

Decorator learning 01

Overview of database recovery

Wonderful review of the digital Expo | highlight scientific research strength, and Zhongchuang computing power won the digital influence enterprise award

Leetcode simple question: find the nearest point with the same X or Y coordinate

Recovery technology with checkpoints

Performance monitoring of database tuning solutions

What if win11 is missing a DLL file? Win11 system cannot find DLL file repair method

boundary IoU 的计算方式

Blocking protocol for concurrency control
随机推荐
点到直线的距离直线的交点及夹角
Recovery technology with checkpoints
Leetcode simple question ring and rod
Performance testing of software testing
Index optimization of performance tuning methodology
New 3D particle function in QT 6.3
Business learning of mall commodity module
Implementation technology of recovery
Decorator learning 01
Oracle triggers
Interview questions for famous enterprises: Coins represent a given value
119. Pascal‘s Triangle II. Sol
Overriding equals() & hashCode() in sub classes … considering super fields
Summary of concurrency control
How to create a thread
[agc009e] eternal average - conclusion, DP
Learning of mall permission module
实战:fabric 用户证书吊销操作流程
Bitbucket installation configuration
Common interview questions of redis factory