Учитывая следующее, поскольку в оригинале не было слишком много информации о классе и т. Д.
Компилятор решит, что новый House (1,2) точно соответствует второму конструктору, и используйте его, обратите внимание, что я получил ответ с наибольшим количеством голосов, и он не сработал.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GenericTest
{
public class House<T>
{
public House(params T[] values)
{
System.Console.WriteLine("Params T[]");
}
public House(int num, T defaultVal)
{
System.Console.WriteLine("int, T");
}
public static House<T> CreateFromDefault<T>(int count, T defaultVal)
{
return new House<T>(count, defaultVal);
}
}
class Program
{
static void Main(string[] args)
{
House<int> test = new House<int>(1, 2); // prints int, t
House<int> test1 = new House<int>(new int[] {1, 2}); // prints parms
House<string> test2 = new House<string>(1, "string"); // print int, t
House<string> test3 = new House<string>("string", "string"); // print parms
House<int> test4 = House<int>.CreateFromDefault<int>(1, 2); // print int, t
}
}
}