Looping through 2 Lists at once

前端 未结 7 439

I have two lists that are of the same length, is it possible to loop through these two lists at once?

I am looking for the correct syntax to do the below



        
7条回答
  •  粉色の甜心
    2021-01-31 11:23

    I have this small function which helps me to iterate through this two list objects. schema is of type SqlData, which is a class that hold three properties. And data is a list that holds values of dynamic type. First I'm iterating through the schema collection and than using the index of item to iterate through the data object.

    public List SqlDataBinding(List schema, List data)
    {
        foreach (SqlData item in schema)
        {
            item.Values = data[schema.IndexOf(item)];
        }
        return schema
    }
    

提交回复
热议问题