C# 从索引范围上的字符串列表中联接字符串

C# 从索引范围上的字符串列表中联接字符串,c#,linq,C#,Linq,我有一个很大的字符串列表,我需要另一个包含字符串的字符串列表。用逗号连接前300个索引,然后再连接300个索引,以此类推。。直到所有字符串都完成。 我在这里展示我所做的 List<string> tempSMSNoList = SMSNos.Split(',').ToList(); // 938 if (tempSMSNoList.Count > 300) { int Quotient = tempSMSNoList.

我有一个很大的字符串列表,我需要另一个包含字符串的字符串列表。用逗号连接前300个索引,然后再连接300个索引,以此类推。。直到所有字符串都完成。 我在这里展示我所做的

    List<string> tempSMSNoList = SMSNos.Split(',').ToList(); // 938
       if (tempSMSNoList.Count > 300)
        {
           int Quotient = tempSMSNoList.Count / 300;   // 3
           int Remainder = tempSMSNoList.Count % 300;  // 38

           List<string> myNewString = new List<string>(); // Need to store new value in this list.
           for(int i=0; i < Quotient; i++)
           {
             // Logic here..
           }
        }
List tempsmnolist=SMSNos.Split(',').ToList();//938
如果(tempsmnolist.Count>300)
{
int Quotient=tempsmnolist.Count/300;//3
int rements=tempsmnolist.Count%300;//38
List myNewString=new List();//需要在此列表中存储新值。
for(int i=0;i<商;i++)
{
//逻辑在这里。。
}
}

首先,您的代码不应该编译,因为
int
类型,而不是包含
Count
属性的类

其次,有一个Linq
Skip
Take
方法可以帮助创建新的值集合

int groupSize = 300;
var numberOfGroups = Quotient + (Remainder > 0 ? 1 : 0); // If there is any remainder then add it as another loop.
for (int i = 0; i < numberOfGroups; i++)
{
    List<string> myNewString = tempSMSNoList.Skip(i*groupSize).Take(groupSize).ToList();
}
int-groupSize=300;
var numberOfGroups=商+(余数>0?1:0);//如果有任何余数,则将其添加为另一个循环。
对于(int i=0;i
您可以使用LINQ来实现这一点

var result = new List<string>();
int groupsize = 300;
for (int i = 0; i< tempSMSNoList.Count(); i+= groupsize)
    result.Add(String.Join(",", tempSMSNoList.Skip(i).Take(groupsize));
var result=newlist();
int groupsize=300;
对于(int i=0;i
那么如何处理3和38呢?非常感谢您的回答,先生。您的回答也解决了我的问题。