linq - Apply lambda expression for specific indices in list c# -



linq - Apply lambda expression for specific indices in list c# -

i new lambda look , have problem convert parts of code involves indices of list within loop equivalent lambda expression.

example 1: working different indices within 1 list

list<double> newlist = new list<double>(); (int = 0; < list.count - 1; ++i) { newlist.add(list[i] / list[i + 1]); }

example 2: working indices 2 lists

double result = 0; (int = 0; < list1.count; ++i) { result += f(list1[i]) * g(list2[i]); }

how write equivalent lambda expressions?

a lambda look looks {params} => {body}, characteristic symbol => "maps to." asking typically referred linq query expressions, come in 2 styles:

the functional style of query typically sequence of chained calls linq extension methods such select, where, take, or tolist. style have used in examples below , much-more prevalent style (in experience).

the "language integrated" style (*) uses built-in c# keywords compiler turn functional style you. example:

var query = employee in employeelist employee.managerid == 17 select employee.name; | compiler v rewrite var query = employeelist .where(employee => employee.managerid == 17) .select(employee => employee.name);

example 1:

var newlist = enumerable.range(0, list.count - 1) .select(i => list[i] / list[i + 1]) .tolist();

example 2:

var result = enumerable.zip(list1.select(f), list2.select(g), (a, b) => * b).sum();

(*) i'm not sure official name it. please right me proper name if know it.

c# linq lambda

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -