
代码
using System;
public interface Catch
{
void Jao();
void He();
int this[int index] { get; set; }
string Name
{
get;
}
}
public class Sub:Catch
{
public void Jao()
{
Console.WriteLine("Jao");
}
public void He()
{
Console.WriteLine("He");
}
public string Name
{
get{return "中国";}
}
int[] num = new int[5];
public int this[int index]
{
get{return num[index];}
set{num[index]=value;}
}
public static void Main()
{
Sub a = new Sub();
a.Jao();
Console.WriteLine(a.Name);
}
}
public interface Catch
{
void Jao();
void He();
int this[int index] { get; set; }
string Name
{
get;
}
}
public class Sub:Catch
{
public void Jao()
{
Console.WriteLine("Jao");
}
public void He()
{
Console.WriteLine("He");
}
public string Name
{
get{return "中国";}
}
int[] num = new int[5];
public int this[int index]
{
get{return num[index];}
set{num[index]=value;}
}
public static void Main()
{
Sub a = new Sub();
a.Jao();
Console.WriteLine(a.Name);
}
}
实现接口的类必须实现接口中所有定义的内容,包括 方法,属性,索引 ,等等。
本文通过一个具体的C#代码示例,详细解析了如何在类中实现接口,包括方法、属性和索引器的实现过程。示例展示了Sub类如何完全实现Catch接口的所有成员。

被折叠的 条评论
为什么被折叠?



