我正在尝试在C#3中学习lambda,并想知道如何使用lambdas编写这个函数:
假设您有Point3值的集合。
对于每一点,p:
创建一个新的p,其中.Y是:
Math.Sin ((center - p).Length * f)
center和f是要提供给函数的外部变量。 Point3类型也有一个带x,y,z值的构造函数。
答案 0 :(得分:7)
输入集合为source
,输出集合为result
:
IEnumerable<Point3> source = ...
IEnumerable<Point3> result = source.Select(p => new Point3(p.x, Math.Sin ((center - p).Length * f), p.z);
答案 1 :(得分:1)
List<Point> oldList = .....;
List<Point> newList = List<Point> ();
double center = ...;
double f = ....;
oldList.ForEach(p=>
newList.Add(new Point(p.X, Math.Sin ((center - p).Length * f), p.Z)););