Created
March 7, 2014 14:53
-
-
Save jbubriski/9412889 to your computer and use it in GitHub Desktop.
Generic Constructor Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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