I have below list
List<int> lstuser = new List<int>();
lstuser.Add(101);
lstuser.Add(102);
lstuser.Add(103);
lstuser.Add(104);
int assigntovariable =0;
I need to assign the above list values to a variable subsequently. That is variable will be inside a for loop & and its length may vary from 1 to any.
for (int i =0;i<10;i++)
{
assigntovariable = //lstuser from one by one in order as
assignedtouser = 101, if i = 0
assignedtouser = 102, if i = 1
assignedtouser = 103, if i = 2
assignedtouser = 104, if i = 3
assignedtouser = 101, if i = 4
assignedtouser = 102, if i = 5
..it will continue till the end of loop
}
Below is what i tried ..but its not good one i think.. please provide me a better solution..Thanks in advance..
<pre lang="C#">List<int> lstuser = new List<int>();
lstuser.Add(101);
lstuser.Add(102);
lstuser.Add(103);
lstuser.Add(104);
int userselected = 0;
int j = 0, x = 0;
for (int i = 0; i < 10; i++)
{
if (x == 0 || x == lstuser.Count)
x = 0;
for (j = x; j < lstuser.Count; j++)
{
if (i > j)
{
userselected = lstuser[j];
if (x == lstuser.Count)
x = 0;
x = j + 1;
}
else
{
userselected = lstuser[i];
x = j+1;
if (x == lstuser.Count)
x = 0;
}
break;
}
int s = userselected;
}</pre>
What I have tried:
List<int> lstuser = new List<int>();
lstuser.Add(101);
lstuser.Add(102);
lstuser.Add(103);
lstuser.Add(104);
int userselected = 0;
int j = 0, x = 0;
for (int i = 0; i < 10; i++)
{
if (x == 0 || x == lstuser.Count)
x = 0;
for (j = x; j < lstuser.Count; j++)
{
if (i > j)
{
userselected = lstuser[j];
if (x == lstuser.Count)
x = 0;
x = j + 1;
}
else
{
userselected = lstuser[i];
x = j+1;
if (x == lstuser.Count)
x = 0;
}
break;
}
int s = userselected;
}