Given the following, since the original did not have too much class information, etc.
The compiler will decide that the new House (1,2) exactly matches the second constructor and uses it, please note that I took the answer with the most votes and it did not work.
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);
lindholm
source share