Consider the following:
static string X() { return "hello"; }
static void Main()
{
Console.WriteLine(X + "goodbye");
}
Do you see the problem? The code concatenates the method X with the string "goodbye". But a method is not something that can be concatenated to a string! The intention was to call the method. The correct code is:
Console.WriteLine(X() + "goodbye");
It is not clear to me from your program fragment what you intend to concatenate in there, but Json
is a method, not something that can be concatenated with a string.
Incidentally, the reason that the compiler is using the somewhat confusing term "method group" in the error is because you might be in this situation:
static string X(int y) { return "hello"; }
static string X(double z) { return "hello"; }
static void Main()
{
Console.WriteLine(X + "goodbye");
}
Now it is unclear which method X
is referring to, and in fact, the C# language says that the expression X
refers to both methods. Such an expression is classified as a "method group". The process of overload resolution picks a unique best method out of a method group.