Skip to content

Instantly share code, notes, and snippets.

@jagregory
Created January 8, 2011 16:13
Show Gist options
  • Save jagregory/770942 to your computer and use it in GitHub Desktop.
Save jagregory/770942 to your computer and use it in GitHub Desktop.
public class Task<T>
{
readonly T something;
public Task(T something)
{
this.something = something;
}
}
public static class Task
{
public static Task<T> New<T>(T something)
{
return new Task<T>(something);
}
}
// find myself using this "pattern" a lot to avoid the rather irritating inability of the C# compiler to infer generic arguments from constructor arguments
var something = "value";
var task = Task.New(something);
// instead of:
var something = "value";
var task = new Task<string>(something);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment