如何将List值作为String传递给Other函数 [英] How to pass the List value as String to the Other function

查看:74
本文介绍了如何将List值作为String传递给Other函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个List<>作为lsSplitMember我通过while循环将它发送到函数

作为字符串。但它抛出异常消息索引超出范围。必须是非负的且小于集合的大小。

我试过以下代码。





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.


//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?

推荐答案

尝试使用
ic--;



之前


before

Process_Split(lsSplitMember[ic]);





你也可以尝试这个



you can try this also

foreach( string s in lsSplitMember )
    Process_Split( s );


因为在C#列表和数组中索引是从 0 n-1 ,你应该改变你的代码:

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


这篇关于如何将List值作为String传递给Other函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆