如何区分方法

本文关键字:方法 何区 | 更新日期: 2023-09-27 17:52:50

using System;
interface one
{
    void getdata();
}
interface two : one
{
  new void getdata();
     void showdata();
}
class intefacehierarchy:two,one
{
    string name;
    public void getdata()
    {
        Console.WriteLine("ok tell me your name");
    }
    public void getdata()
    {
        Console.WriteLine("Enter the name");
        name = Console.ReadLine();
    }
    public void showdata()
    {
        Console.WriteLine(String.Format("hello mr. {0}", name));
    }
}

如何区分方法

好吧,这只是一个猜测,因为你并没有真正问一个问题,但是你可以使用显式接口实现:

class intefacehierarchy:two,one
{
    string name;
    // implements two.getdata
    public void getdata()
    {
        Console.WriteLine("ok tell me your name");
    }
    // implements one.getdata explicitly
    void one.getdata()
    {
        Console.WriteLine("Enter the name");
        name = Console.ReadLine();
    }
    // implements two.showdata
    public void showdata()
    {
        Console.WriteLine(String.Format("hello mr. {0}", name));
    }
}