Created
October 21, 2018 12:18
-
-
Save mariusGundersen/7092b846fdee640ecd7e1f37eee7255c to your computer and use it in GitHub Desktop.
Duct-typed extension methods Example 6
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
// 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