Skip to content

Instantly share code, notes, and snippets.

@mariusGundersen
Created October 21, 2018 12:18
Show Gist options
  • Save mariusGundersen/7092b846fdee640ecd7e1f37eee7255c to your computer and use it in GitHub Desktop.
Save mariusGundersen/7092b846fdee640ecd7e1f37eee7255c to your computer and use it in GitHub Desktop.
Duct-typed extension methods Example 6
// Example 6: Add a list
// This is just a dummy method that returns some ints
public static IEnumerable<int> GetAnotherListOfInts()
=> new[] { 10, 11, 12, 13 };
// With this extension method...
public static void Add<T>(this List<T> list, IEnumerable<T> items)
=> list.AddRange(items);
// ...this is possible
var result = new List<int>
{
1,
2,
GetAnotherListOfInts(),
3
};
// Output each item, to see if things work correctly
foreach(var item in result){
Console.WriteLine(item);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment