제네릭 형식 인수를 사용하는 함수가 있습니다. 그것은 꽤 간단합니다C#에서 형식 인수를 지정하지 않아도되는 이유는 무엇입니까?
private static void Run<T>(IList<T> arg)
{
foreach (var item in arg)
{
Console.WriteLine(item);
}
}
나는 형식 인수를 지정하지 않고이 함수를 호출 할 수 있다는 것을 발견했습니다
static void Main(string[] args)
{
var list = new List<int> { 1, 2, 3, 4, 5 };
//both of the following calls do the same thing
Run(list);
Run<int>(list);
Console.ReadLine();
}
이 컴파일과 잘 실행됩니다. 형식 인수를 지정하지 않고이 기능이 작동하는 이유는 무엇입니까? 코드에서 T
이 int임을 어떻게 알 수 있습니까? 이 이름이 있나요?
입니다 –