using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Foo f = new Foo();
int i= f.Test();
string s = f.Test();
Console.WriteLine("{0}=={1}", i, s);
}
}
public class Foo
{
public int GetA()
{
return 1;
}
public string GetB()
{
return "B";
}
public Help Test()
{
return new Help(this);
}
}
public struct Help
{
Foo foo;
public Help(Foo foos)
{
this.foo = foos;
}
public static implicit operator int(Help help)
{
return help.foo.GetA();
}
public static implicit operator string(Help help)
{
return help.foo.GetB();
}
}
}
implicit operator返回相同方法重载
最新推荐文章于 2024-08-13 16:42:06 发布