日期:2014-05-20  浏览次数:20984 次

问一下数组的问题!!
C# code

 string shuzi = ",04,06,19,23,25,28,06,03,04,13,24,31,32,04,07,11,15,17,21,26,14,01,12,14,17,22,25,11,02,04,06,15,17,30,14";

        //假如现在有这样一组数字,我想得到每7个数字为一组,例如第一组为:04,06,19,23,25,28,06
        //我想在一个for循环里面得到这样
        int h1, h2, h3, h4, h5, h6, h7;
        for()
        {
        //每循环一次,得到一组,
            h1=;
        h2=;
        h3=;
        h4=;
        h5=;
        h6=;
        h7=;

        }




------解决方案--------------------
Math.Round(Decimal d)函数,向上取整啊,比如Math.Round(0.666),Math.Round(Decimal d)用它处理后,等于1
------解决方案--------------------
class Program
{
static void Main(string[] args)
{
char[] separator = { ',' };
var str = ",04,06,19,23,25,28,06,03,04,13,24,31,32,04,07,11,15,17,21,26,14,01,12,14,17,22,25,11,02,04,06,15,17,30,14";
var arr = str.Split(separator, StringSplitOptions.RemoveEmptyEntries);
for (var i = 0; i < arr.Length; i += 7)
{
var group = arr.Skip(i).Take(7).ToArray();
Debug.WriteLine(string.Join(",", group));
}

}
}