static void Main(string[] args)
{
TEST tEST = new TEST { Hello = 100 };
TEST_ST tEST_ST = (TEST_ST)tEST;
Console.WriteLine(tEST_ST.Hello);
tEST_ST = new TEST_ST() { Hello = 111 };
TEST tEST1 = (TEST)tEST_ST;
Console.WriteLine(tEST1.Hello.ToString());
Console.ReadKey();
}
public class TEST
{
public int Hello { get; set; }
public static explicit operator TEST(TEST_ST st)
{
TEST tEST = new TEST() { Hello = st.Hello };
return tEST;
}
}
public struct TEST_ST
{
public int Hello;
public static explicit operator TEST_ST(TEST test)
{
TEST_ST tEST = new TEST_ST() { Hello = test.Hello };
return tEST;
}
}
输出:
100
111
标签:C#,public,explicit,operator,ST,tEST,显式,TEST,Hello
From: https://www.cnblogs.com/huvjie/p/17381911.html