Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a List<> as lsSplitMember I am sending it through the while loop to the function
as a string.But it throws exception message "Index was out of range. Must be non-negative and less than the size of the collection".
I have tried with following code.


C#
//Globally declared variable lsSplitMember
 List<String> lsSplitMember=new List<String>();


  int ic = lsSplitMember.Count();
   while (ic != 0)
   {
      Process_Split(lsSplitMember[ic]);
      ic--;
   }

   Protected void Process_Split(String Member)
   {
     //Some Code
   }

So how can I Solve this problem?
Posted

try to use
C#
ic--;

before
C#
Process_Split(lsSplitMember[ic]);


you can try this also
C#
foreach( string s in lsSplitMember )
    Process_Split( s );
 
Share this answer
 
v3
Because in C# list and arrays the index are from 0 to n-1, you should change your code like this:
C#
int ic = lsSplitMember.Count();
while (ic > 0) //Here!
   {
      ic --; //Moved here!
      Process_Split(lsSplitMember[ic]);
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900