c# - 为什么不能在 C# 中进行多重继承?

标签 c# .net

<分区>

Possible Duplicate:
Should C# include multiple inheritance?

为什么c#不支持多重继承?

public partial class Child: Parent1 
{
  void MakeParent1Mad();
}

public partial class Child: Parent2
{
  void MakeParent2Mad();
}

最佳答案

http://blogs.msdn.com/b/dachou/archive/2008/04/17/net-and-multiple-inheritance.aspx

  • .NET was designed to support multiple languages, but not all languages can effectively support multiple inheritance. Or technically they could, but the complexities added in language semantics would make some of those languages more difficult to use (and less similar to their roots, like VB, and for backward compatibility reasons) and not worth the trade-off of being able to reuse code in the manner of multiple inheritance
  • It would also make cross-language library interoperability (via CLS compliance) less of a reality than it is today, which is one of the most compelling features of .NET. There are over 50 languages supported on .NET in over 70 implementations today
  • The most visible factor is language semantics complexity. In C++ we needed to add explicit language features in order to address ambiguities (such as the classic diamond problem) caused by multiple inheritance, such as the "virtual" keyword to support virtual inheritance to help the compiler resolve inheritance paths (and we had to use it correctly too)
  • As we know code is written 20% of the time, but read 80% of the time. Thus advocates on simplicity side prefer not to add language features for the sake of keeping semantics simple. In comparison C# code is significantly simpler to read than C++ code, and arguably easier to write

关于c# - 为什么不能在 C# 中进行多重继承?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3408590/

相关文章:

c# - 如何在出现异常时关闭 DataReader

c# - 定时器数量过多会影响定时器触发吗?

c# - .NET Real-Time 和 TaskMgr Real-time 优先级类之间有什么区别?

c# - Unity防止点击1s

c# - 在使用 Task.Run() 创建的任务上调用 await

c# - 带有 WHERE 条件的 XElement LINQ 失败

c# - 按 Enter 键时调用按钮单击事件 - c#

c# - Amazon S3 TransferUtility.Upload 在 C# 中挂起

c# - 并行事件订阅者 .net 4.5

c# - Xtra Grid 在运行时排序数据?