小编Ald*_*ert的帖子

结构化类和反向隐式转换

假设我有一个结构和一个具有相同成员的类:

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)

c# implicit-conversion

0
推荐指数
1
解决办法
53
查看次数

标签 统计

c# ×1

implicit-conversion ×1