interface IBaseType
{
void Add(string NewID,bool newBool) ;
void Add(string NewID,int newInt);
void Add(string NewID,float newFloat);
}
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1:IBaseType
{
public void Add(string NewId, bool newBool)
{
Console.WriteLine("parameter is {0} and {1}",NewId,newBool);
}
public void Add(string NewID,int newInt)
{
Console.WriteLine("parameter is {0} and {1}",NewID,newInt);
}
public void Add(string NewID,float newFloat)
{
Console.WriteLine("parameter is {0} and {1}",NewID,newFloat);
}
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Class1 c=new Class1();
c.Add("first",true);
c.Add("second",16);
c.Add("third",12.2f);
}
//
// TODO: 在此处添加代码以启动应用程序
//
}
{
void Add(string NewID,bool newBool) ;
void Add(string NewID,int newInt);
void Add(string NewID,float newFloat);
}
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1:IBaseType
{
public void Add(string NewId, bool newBool)
{
Console.WriteLine("parameter is {0} and {1}",NewId,newBool);
}
public void Add(string NewID,int newInt)
{
Console.WriteLine("parameter is {0} and {1}",NewID,newInt);
}
public void Add(string NewID,float newFloat)
{
Console.WriteLine("parameter is {0} and {1}",NewID,newFloat);
}
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Class1 c=new Class1();
c.Add("first",true);
c.Add("second",16);
c.Add("third",12.2f);
}
//
// TODO: 在此处添加代码以启动应用程序
//
}
static void Main(string[] args)
{
Class1 c=new Class1();
c.Add("first",true);
c.Add("second",16);
c.Add("third",12.2f);
IBaseType ibt=(IBaseType)c;//可加is或as
ibt.Add("one",false);
ibt.Add("two",32);
ibt.Add("three",111.1111f);
}
static void Main(string[] args)
{
Class1 c=new Class1();
c.Add("first",true);
c.Add("second",16);
c.Add("third",12.2f);
IBaseType ibt=(IBaseType)c;
ibt.Add("one",false);
ibt.Add("two",32);
ibt.Add("three",111.1111f);
}
interface IBaseType
{
void Add(string NewID,bool newBool) ;
void Add(string NewID,int newInt);
}在一个派生类中我继承他
public class Bool:System.Collections.DictionaryBase,IBaseType
{ public Bool()
{
} public void Add(string newID,bool newBool)
{
Dictionary.Add(newID,newBool) ;
}//仅实现其中一个
}//在编译时出错提示“Bool”不会实现接口成员“IBaseType.Add(string, int)”“我想在另一个类中实现IBaseType.Add(string, int) !”