Skip to content

Instantly share code, notes, and snippets.

@ondrasek
Created February 12, 2019 23:15
Show Gist options
  • Save ondrasek/7290806de5ce65db43a64ee70ab952bd to your computer and use it in GitHub Desktop.
Save ondrasek/7290806de5ce65db43a64ee70ab952bd to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
namespace linq_select
{
public class Holder
{
public object arg1 { get; set; }
public object arg2 { get; set; }
public Holder(object arg1, object arg2)
{
Console.WriteLine($"ctor: {arg1}, {arg2}");
this.arg1 = arg1;
this.arg2 = arg2;
}
public override string ToString()
=> $"Holder({arg1}, {arg2})";
}
class Program
{
static IEnumerable<(string, int)> Data()
{
yield return ("a", 1);
yield return ("b", 2);
yield return ("c", 3);
}
static void Main(string[] args)
{
var data = Data();
var newData = data.Select((s, i) => {
Console.WriteLine($"got: {s}, {i}");
return new Holder(s, i);
});
Console.WriteLine("--");
foreach (object item in newData)
Console.WriteLine(item);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment