我有一个很大的字符串列表,并且我需要另一个包含string.string的列表,该列表由前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..
}
}
答案 0 :(得分:1)
首先,由于if (!defined('SECURE')) {
die();
}
是Quotient
类型,而不是包含int
属性的类,因此您的代码不应编译。
第二,有一个Linq Count
和Skip
方法可以帮助收集新的值。
Take
答案 1 :(得分:0)
您可以为此使用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));