Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot implicitly convert in async method [duplicate]

The following code doesn't compile, and I fail to understand why

namespace ImplicitConversion
{
    struct Wrapper<T>
    {
        public static implicit operator Wrapper<T> (T input)
        {
            return new Wrapper<T> ();
        }
    }

    interface IFoo
    {
    }

    class Foo:IFoo
    {
    }

    class MainClass
    {
        public static void Main (string[] args)
        {       
        }

        static Wrapper<IFoo> Test ()
        {
            IFoo foo = new Foo ();
            return foo; // Cannot implicitly convert type 'ImplicitConversion.IFoo' to 'ImplicitConversion.Wrapper<ImplicitConversion.IFoo>' (CS0029) (ImplicitConversion)
        }
    }
}

Why can't I use the implicit conversion?

like image 786
miniBill Avatar asked May 30 '26 10:05

miniBill


1 Answers

As DLeh mentioned it is not about async.

AFAIK interfaces can not be converted(either implicit or explicit).

See this answer for details: https://stackoverflow.com/a/143567/526704

like image 79
serdar Avatar answered Jun 01 '26 00:06

serdar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!