Skip to content
Hendrik Bulens edited this page Jul 21, 2021 · 2 revisions

SelectTry

static bool ParseId(Client client, out int number)
{
  number = client.Id;
  return true;
}

List<Customer> customers = new()
{
  new Customer(1, "Hello", "World"),
  new Customer(5, "Hello", "World"),
  new Customer(15, "Hello", "World")
};

IEnumerable<int> identifiers = customers.SelectTry<Customer, Client, int>(x => new Client() { Id = x.Id }, ParseId);
int identifiersSum = identifiers.Sum(); // 21

ConvertTo

IEnumerable<int> integerList = new List<int> { 1, 2, 3, 4, 5 };
IEnumerable<long> longList = integerList.ConvertTo<int, long>();
int count = longList.Count(); // 5
Clone this wiki locally