Skip to content

Instantly share code, notes, and snippets.

@jbubriski
Created March 7, 2014 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbubriski/9412889 to your computer and use it in GitHub Desktop.
Save jbubriski/9412889 to your computer and use it in GitHub Desktop.
Generic Constructor Example
using System;
namespace GenericConstructorTest
{
class Program
{
static void Main(string[] args)
{
// This doesn't compile
var myClass1 = new MyClass(5, 6);
// You have to do this
var myClass2 = new MyClass<int, int>(5, 6);
}
}
public class MyClass<T1, T2>
{
public MyClass(T1 a, T2 b)
{
}
public MyClass<T1, T2> Create<T1, T2>(T1 a, T2 b)
{
return new MyClass<T1, T2>(a, b);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment