Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在一个函数中使用两个单独列表中的数据?_C#_List - Fatal编程技术网

C# 在一个函数中使用两个单独列表中的数据?

C# 在一个函数中使用两个单独列表中的数据?,c#,list,C#,List,基本上,我的程序有一部分(用于向量求解)应该从两个列表(listVectorMagnitude和listVectorAngle)中获取数据,然后通过一个函数运行它们 在单独的类(vectorXComponent)中,然后返回值。我如何准确地获取listVectorMagnitude中的第一个值,listVectorAngle中的第一个值,然后将它们用作vectorXComponent函数中的参数?它将对列表中的值进行迭代。谢谢。你没有提供太多细节。我假设您有一个名为Bar的类Bar的实例,该类有

基本上,我的程序有一部分(用于向量求解)应该从两个列表(listVectorMagnitude和listVectorAngle)中获取数据,然后通过一个函数运行它们
在单独的类(vectorXComponent)中,然后返回值。我如何准确地获取listVectorMagnitude中的第一个值,listVectorAngle中的第一个值,然后将它们用作vectorXComponent函数中的参数?它将对列表中的值进行迭代。谢谢。

你没有提供太多细节。我假设您有一个名为
Bar
的类
Bar
的实例,该类有一个名为
vectorXComponent
的方法。此外,我假设
Bar.vectorXComponent
的返回类型是
Foo

现代功能方式:

var xComponents = listVectorMagnitude.Zip(
                      listVectorAngle,
                      (x, y) => bar.vectorXComponent(x, y)
                  );
或者,一个老式的
for
循环:

List<Foo> xComponents = new List<Foo>();
for(int i = 0; i < listVectorMagnitude.Count; i++) {
    xComponents.Add(bar.vectorXComponent(
        listVectorMagnitude[i],
        listVectorAngle[i])
    );
}
List xComponents=new List();
for(int i=0;i
您是否尝试在列表中迭代,使用每对项作为函数的参数?是否可以发布您当前拥有的代码?显示一些代码作为您尝试执行的示例,以便我们提供相应的建议。您是否在询问如何将值作为参数传递给函数?如果是这样的话,你可能只想拿起一本关于学习C#的书。顺便说一句:你可能想创建或使用一个结合了角度和幅度的向量类。它避免了当你的两个列表长度不同时出现的麻烦。谢谢!这就是我要找的。我想补充一点,我认为它可能类似于Python中的Zip函数,但我不确定。