界面问题请帮忙 [英] interface issue please help

查看:69
本文介绍了界面问题请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public interface Iname
  {
      void display();
  }

  public interface Iname2
  {
      void display();
  }

  class Program
  {
       static void Main(string[] args)
      {
          cl obj = new cl();
          obj.display();
            Console.ReadLine();
      }
        }

  class cl : Iname, Iname2
  {
  public void display()
  {
      Console.WriteLine("speed is 300");
  }
  }


在这里,我的困惑是:恰好在上面实现了显示"(接口1或接口2")和n ..

我很困惑..需要帮助...吗?


here my confusion is :just above which ''display''( Interface 1 or interface 2''s) got implemented ans the ncalled..

i am confused..need help...?

推荐答案

已实现的功能实际上是您在类cl中定义的功能.该界面仅提供了我所遵循的类的模板.

在这种情况下,因为您是从2个接口派生而来的,每个接口都具有具有相同签名的功能,因此可以满足这两个接口定义.
The function that got implemented is actually the function defined in you class cl. The interface is only providing a template that the class my adhere to.

In this case as you are deriving from 2 interfaces that each have a function with the same signature and therefore fulfilling both interface definitions.


答案是:两者.请参见此处
除非您明确实现.请参见此处

您可以使用
进行测试
The answer is: both. See here
Unless you implement then explicitely. See here

You can test with
public interface Iname
{
   void display();
}
 
public interface Iname2
{
   void display();
}
 
class Program
{
    static void Main(string[] args)
    {
	cl obj = new cl();
	Iname i1 = obj as Iname;
	i1.display();
	
	Iname2 i2 = obj as Iname2;
	i2.display();		
        System.Console.ReadLine();
    }
}
 
class cl : Iname, Iname2
{
    public void display()
    {
        System.Console.WriteLine("speed is 300");
    }
}


尝试此链接

http://msdn.microsoft.com/en-us/library/ms173157.aspx [ ^ ]
try this link

http://msdn.microsoft.com/en-us/library/ms173157.aspx[^]


这篇关于界面问题请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆