C#: Cleanest way to divide a string array into N instances N items long

后端 未结 8 1404
我寻月下人不归
我寻月下人不归 2020-12-23 10:40

I know how to do this in an ugly way, but am wondering if there is a more elegant and succinct method.

I have a string array of e-mail addresses. Assume the string

8条回答
  •  长情又很酷
    2020-12-23 11:22

    Assuming you are using .NET 3.5 and C# 3, something like this should work nicely:

    string[] s = new string[] {"1", "2", "3", "4"....};
    
    for (int i = 0; i < s.Count(); i = i + 50)
    {
        string s = string.Join(";", s.Skip(i).Take(50).ToArray());
        DoSomething(s);
    }
    

提交回复
热议问题