C#中的多重继承

前端之家收集整理的这篇文章主要介绍了C#中的多重继承前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我作为C#开发人员工作时,我知道我们可以通过使用Interface实现多重继承.

任何人都可以提供链接代码,了解如何使用C#实现多重继承.

我想要使​​用Interface在C#中实现多重继承的代码.

提前致谢.

解决方法

这是一个很好的例子.

http://blog.vuscode.com/malovicn/archive/2006/10/20/How-to-do-multiple-inheritance-in-C_2300_-2D00-Implementation-over-delegation-_2800_IOD_2900_.aspx

快速代码预览:

interface ICustomerCollection
{
      void Add(string customerName);
      void Delete(string customerName);
}

class CustomerCollection : ICustomerCollection
{
      public void Add(string customerName)
      {
            /*Customer collection add method specific code*/
      }
      public void Delete(string customerName)
      {
            /*Customer collection delete method specific code*/
      }
}

class MyUserControl: UserControl,ICustomerCollection
{
      CustomerCollection _customerCollection=new CustomerCollection();

      public void Add(string customerName)
      {
            _customerCollection.Add(customerName);
      }
      public void Delete(string customerName)
      {
            _customerCollection.Add(customerName);
      }
}
原文链接:https://www.f2er.com/csharp/98947.html

猜你在找的C#相关文章