Skip to content

Instantly share code, notes, and snippets.

@lisardggY
Created November 26, 2015 09:01
Show Gist options
  • Save lisardggY/947747cad784d5231830 to your computer and use it in GitHub Desktop.
Save lisardggY/947747cad784d5231830 to your computer and use it in GitHub Desktop.
Find yourself wrapping single objects in arrays or lists to pass to multi-value APIs? Tired of writing new [] {myObject}; all the time? These extension methods will make your collection-wrapping fluent and painless.
public static T[] AsSingletonArray<T>(this T single)
{
return new[] {single};
}
public static List<T> AsSingletonList<T>(this T single)
{
return new List<T> {single};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment