Given the following code;
using System;
public class Program
{
class Example
{
static void F(object x) => Console.WriteLine("F(object)");
static void F<T>(T x) => Console.WriteLine($"F<T>(T), T is {typeof(T)}");
public static void UsageExample()
{
F("abc");
}
}
public static void Main()
{
Example.UsageExample();
}
}
I don't understand how the compiler is selecting which function to invoke for method; F("abc");. What is the criteria, how I did not implicitly invoke F("abc").
When I executed the app, I expected F("abc") to return;
"F(object)" -- "abc" is an object and a System.String
but it return;
"F(T), T is System.String"
instead; I did not invoke F<string>("abc")
so how did it know to use;
static void F(T x) => Console.WriteLine($"F(T), T is {typeof(T)}"); ??
In other words, why doesn't F(object x)
capture F("abc") before static void F<T>(T x)
?