假设我有一个结构和一个具有相同成员的类:
using System;
class app
{
static void Main()
{
foo f = new foo() { a = 4, b = 7 };
bar b = f;
Console.WriteLine(b.a);
Console.ReadKey();
}
struct foo
{
public int a { get; set; }
public uint b { get; set; }
}
class bar
{
public int a { get; set; }
public uint b { get; set; }
public static implicit operator foo(bar b)
{
return b;
}
public static implicit operator bar(foo …Run Code Online (Sandbox Code Playgroud)