Repeat list endlessly (Zip a finite list with an Infinite repeating sequence)

前端 未结 2 1799
眼角桃花
眼角桃花 2021-01-14 03:13

UserList is a list of dictionaries, like:

[
  {Name:\"Alex\",Age:25},
  {Name:\"Peter\",Age:35},
  {Name:\"Muhammad\",Age:28},
  {Name:\"Raul\",         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-14 03:51

    Something like this should do the trick:

    var i = 0;
    var l = RowColorList.Count;
    UserList.ForEach(user => user.Add("RowColor", RowColorList[(i++) % l]));
    

    The % operator will guarantee "cyclic" access to the RowColorList.

提交回复
热议问题