Adding/summing two arrays

前端 未结 5 1331
抹茶落季
抹茶落季 2021-01-31 02:51

I\'ve encountered a purely hypothetical problem which feels like it has an easy solution if I find the right linq method...

I have two arrays of ints and I know they are

5条回答
  •  一整个雨季
    2021-01-31 03:03

    Without LINQ:

    private static IEnumerable AddArrays(IEnumerable a1, IEnumerable a2)
    {
        var e1 = a1.GetEnumerator();
        var e2 = a2.GetEnumerator();
    
        while (e1.MoveNext() && e2.MoveNext())
            yield return e1.Current + e2.Current;
    }
    

提交回复
热议问题