G
Guest
I found a really strange quirk in the C# compiler, which I can't beleive is
proper behaviour. If I define a class thus:
public class MyClass
{
public override string ToString()
{
return base.ToString();
}
}
and then call it thus:
MyClass myClass = new MyClass();
string test1 = myClass;
it does not compile, because it cannot implicitly convert myClass to a string.
But if I call it thus:
MyClass myClass = new MyClass();
string test1 = myClass + "";
it compiles fine. I'd be interested to know if anyone thinks that makes sense.
proper behaviour. If I define a class thus:
public class MyClass
{
public override string ToString()
{
return base.ToString();
}
}
and then call it thus:
MyClass myClass = new MyClass();
string test1 = myClass;
it does not compile, because it cannot implicitly convert myClass to a string.
But if I call it thus:
MyClass myClass = new MyClass();
string test1 = myClass + "";
it compiles fine. I'd be interested to know if anyone thinks that makes sense.