Skip to content

Instantly share code, notes, and snippets.

@mariusGundersen
Created October 21, 2018 12:18
Show Gist options
  • Select an option

  • Save mariusGundersen/7092b846fdee640ecd7e1f37eee7255c to your computer and use it in GitHub Desktop.

Select an option

Save mariusGundersen/7092b846fdee640ecd7e1f37eee7255c to your computer and use it in GitHub Desktop.

Revisions

  1. mariusGundersen created this gist Oct 21, 2018.
    23 changes: 23 additions & 0 deletions Example6.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    // 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);
    }