The following code fails to compile with the error Cannot implicitly convert type 'string' to 'String'
in C#.
void Main()
{
Console.Write("Hello".Append("Mark"));
}
public static class Ext
{
public static String Append<String>(this String str, String app)
{
return str + " " + app;
}
}
You can fix the compile error by removing the Type parameter from the extension method but I'm wondering why this fails to compile given that typeof(string) == typeof(String)
evaluates to true
.
The following also works just fine:
void Main()
{
Console.Write("Hello".Append("Mark"));
}
public static class Ext
{
public static string Append<String>(this String str, string app)
{
return str + " " + app;
}
}