实现接口的步骤前面带接口名是什么意思
实现接口的方法前面带接口名是什么意思?
EnumLoginState IUserLogin.AdminLogin(string UserName, string PassWord, out GlobalUserInfo info)
某个类实现IUserLogin接口的AdminLogin方法,可是在实现方法的时候这么写是个什么意思,为什么方法前还要带个接口名啊?
------解决方案--------------------
------解决方案--------------------
If a class implements two interfaces that contain a member with the same signature, then implementing that member on the class will cause both interfaces to use that member as their implementation. In the following example, all the calls to Paint invoke the same method.
来自
http://msdn.microsoft.com/en-us/library/ms173157.aspx
它的副作用是方法只能通过接口的引用调用,不能通过类的引用调用。有时候会故意这样用。
------解决方案--------------------
显示的实现接口的方法,在多接口继承的时候可能会用到
------解决方案--------------------
就是
IUserLogin login = new UserLogin()
login.AdminLogin
UserLogin login2 = new UserLogin();//这样是可以的~
login2.AdminLogin //然后这样就有问题了~ 简单来你,你只能通过接口的方式调用我~
不能直接用实现类
你可以敲敲上面的代码
然后把IUserLogin去掉和加上,看看VS会给你什么提示,然后你就懂了~
EnumLoginState IUserLogin.AdminLogin(string UserName, string PassWord, out GlobalUserInfo info)
某个类实现IUserLogin接口的AdminLogin方法,可是在实现方法的时候这么写是个什么意思,为什么方法前还要带个接口名啊?
------解决方案--------------------
C# 接口 与重写
namespace QQ601906420
{
interface IAA
{
void AA1F();
void AA2F();
void AA3F();
}
class BB : IAA
{
void IAA.AA1F() { Console.WriteLine("BB.IAA.AA1F"); }
public void AA2F() { Console.WriteLine("BB.AA2F"); }
public virtual void AA3F() { Console.WriteLine("BB.AA3F"); }
}
class CC:BB,IAA
{
void AA1F() { Console.WriteLine("CC.AA1F"); }
void IAA.AA2F() { Console.WriteLine("CC. IAA.AA2F"); }
public override void AA3F(){ Console.WriteLine("CC.AA3F"); }
static void Main()
{
//Console.WriteLine("------------CC-----------");
CC c = new CC();
c.AA1F();
c.AA2F();
c.AA3F();
//Console.WriteLine("-----------------------");
IAA ia = c;
ia.AA1F();
ia.AA2F();
ia.AA3F();
//Console.WriteLine("----------BB-------------");
BB b = new BB();
b.AA1F();
b.AA2F();
b.AA3F();
//Console.WriteLine("-----------------------");
ia = b;
ia.AA1F();
ia.AA2F();
ia.AA3F();
Console.ReadLine();
}
}
}
------解决方案--------------------
If a class implements two interfaces that contain a member with the same signature, then implementing that member on the class will cause both interfaces to use that member as their implementation. In the following example, all the calls to Paint invoke the same method.
来自
http://msdn.microsoft.com/en-us/library/ms173157.aspx
它的副作用是方法只能通过接口的引用调用,不能通过类的引用调用。有时候会故意这样用。
------解决方案--------------------
显示的实现接口的方法,在多接口继承的时候可能会用到
------解决方案--------------------
就是
IUserLogin login = new UserLogin()
login.AdminLogin
UserLogin login2 = new UserLogin();//这样是可以的~
login2.AdminLogin //然后这样就有问题了~ 简单来你,你只能通过接口的方式调用我~
不能直接用实现类
你可以敲敲上面的代码
然后把IUserLogin去掉和加上,看看VS会给你什么提示,然后你就懂了~