What does the C# compiler mean when it prints "an explicit conversion exists"?

Posted by Wim Coenen on Stack Overflow See other posts from Stack Overflow or by Wim Coenen
Published on 2010-03-26T16:09:28Z Indexed on 2010/03/26 16:13 UTC
Read the original article Hit count: 253

Filed under:

If I make an empty test class:

public class Foo
{
}

And I try to compile code with this statement:

Foo foo = "test";

Then I get this error as expected:

Cannot implicitly convert type 'string' to 'ConsoleApplication1.Foo'

However, if I change the declaration of Foo from class to interface, the error changes to this (emphasis mine):

Cannot implicitly convert type 'string' to 'ConsoleApplication1.Foo'. An explicit conversion exists (are you missing a cast?)

What is this "explicit conversion" which is supposed to exist?

© Stack Overflow or respective owner

Related posts about c#