How to iterate over two arrays at once?

后端 未结 6 1276
我在风中等你
我在风中等你 2020-12-14 20:44

I have two arrays built while parsing a text file. The first contains the column names, the second contains the values from the current row. I need to iterate over both list

6条回答
  •  执笔经年
    2020-12-14 21:08

    If you're really using arrays, the best way is probably just to use the conventional for loop with indices. Not as nice, granted, but as far as I know .NET doesn't offer a better way of doing this.

    You could also encapsulate your code into a method called zip – this is a common higher-order list function. However, C# lacking a suitable Tuple type, this is quite crufty. You'd end up returning an IEnumerable> which isn't very nice.

    By the way, are you really using IEnumerable instead of IEnumerable or why do you cast the Current value?

提交回复
热议问题