C# 有没有办法将2个元素中的元素求和到c中的新列表中#

C# 有没有办法将2个元素中的元素求和到c中的新列表中#,c#,list,C#,List,我有两个相同计数的不同列表,我正试图将它们汇总成一个新列表 List<int> Calculate = new List<int>(); List<int> new_Quantity= new List<int>(); List<int> Qty= new List<int>(); 但是它没有得到我想要的精确计算,因为这个输出是[4,7,9,4,7,9,4,7,9]; 那么我该如何解决这个问题呢?列出3个列表: st

我有两个相同计数的不同列表,我正试图将它们汇总成一个新列表

 List<int> Calculate = new List<int>();
 List<int> new_Quantity= new List<int>();
 List<int> Qty= new List<int>();
但是它没有得到我想要的精确计算,因为这个输出是[4,7,9,4,7,9,4,7,9]; 那么我该如何解决这个问题呢?

列出3个列表:

static List<int> List1 = new List<int>();
static List<int> List2 = new List<int>();
static List<int> List3 = new List<int>();


void Sample()
    {
        List1.Add(2);
        List2.Add(3);

        for(int i=0;i<List1.Count();i++)
        {
            List3.Add(List1[i] + List2[i]);
        }
    }
静态列表列表1=新列表();
静态列表List2=新列表();
静态列表List3=新列表();
无效样本()
{
清单1.添加(2);
清单2.添加(3);

for(int i=0;我必须使用for循环和
result[i]=list1[i]+list2[i];
或者如果您想尝试Linq签出
Enumerable.Zip
var third=first.Zip(second,(f,s)=>f+s)
@rufus…这是c#@Haywhy是的,你为什么要问?这对你不起作用吗?你有更具体的问题吗?@rufus,已经更新了问题列表qtyNumbers=new List();@Haywhy这段代码也会做你所问的。如果没有回答,请将你的问题缩小到更具体的范围(除了修改
实例
类中的
静态
成员之外,根据需求可能会出现问题)。
static List<int> List1 = new List<int>();
static List<int> List2 = new List<int>();
static List<int> List3 = new List<int>();


void Sample()
    {
        List1.Add(2);
        List2.Add(3);

        for(int i=0;i<List1.Count();i++)
        {
            List3.Add(List1[i] + List2[i]);
        }
    }