C#行表现得很奇怪而不是我想要的方式

时间:2013-11-12 03:17:21

标签: c# row

我正在使用C#,我想更改输出视图。原始输出就是这个。

|---------------|---------------|-----------------|
| Student Name  | Student Year  | Student Teacher |
|---------------|---------------|-----------------|
| StudentName01 | Junior        | Ms. Mandy       |
| StudentName02 | Junior        | Ms. Mandy       |
| StudentName03 | Junior        | Ms. Mandy       |
| StudentName04 | Junior        | Ms. Mandy       |
| StudentName05 | Junior        | Ms. Mandy       |
| StudentName06 | Junior        | Ms. Mandy       |
| StudentName07 | Junior        | Ms. Mandy       |
| StudentName08 | Junior        | Ms. Mandy       |
| StudentName09 | Junior        | Ms. Mandy       |
| StudentName10 | Junior        | Ms. Mandy       |
|---------------|---------------|-----------------|

目标输出:

    |---------------|---------------|-----------------|---------------|---------------|-----------------|
    | Student Name  | Student Year  | Student Teacher | Student Name  | Student Year  | Student Teacher |
    |---------------|---------------|-----------------|---------------|---------------|-----------------|
    | Martha        | Junior        | Ms. Mandy       | Barry         | Junior        | Ms. Mandy       |
    | Joseph        | Junior        | Ms. Mandy       | Cathy         | Junior        | Ms. Mandy       |
    | Adam          | Junior        | Ms. Mandy       | Elle          | Junior        | Ms. Mandy       |
    | Lyn           | Junior        | Ms. Mandy       | Faye          | Junior        | Ms. Mandy       |
    | Drew          | Junior        | Ms. Mandy       | Gary          | Junior        | Ms. Mandy       |
    |---------------|---------------|-----------------|---------------|---------------|-----------------| 

当前输出:

|---------------|---------------|-----------------|---------------|---------------|-----------------|
| Student Name  | Student Year  | Student Teacher | Student Name  | Student Year  | Student Teacher |
|---------------|---------------|-----------------|---------------|---------------|-----------------|
| Martha        | Junior        | Ms. Mandy       |               |               |                 |  
| Joseph        | Junior        | Ms. Mandy       |               |               |                 |   
| Adam          | Junior        | Ms. Mandy       |               |               |                 | 
| Lyn           | Junior        | Ms. Mandy       |               |               |                 |
| Drew          | Junior        | Ms. Mandy       |               |               |                 |
|               |               |                 | Barry         | Junior        |  Ms. Mandy      |
|               |               |                 | Cathy         | Junior        |  Ms. Mandy      | 
|               |               |                 | Elle          | Junior        |  Ms. Mandy      |
|               |               |                 | Faye          | Junior        |  Ms. Mandy      |
|               |               |                 | Gary          | Junior        |  Ms. Mandy      |
|---------------|---------------|-----------------|---------------|---------------|-----------------|

这是我的代码,我正在获得当前输出。我应该添加什么才能获得目标输出?

CString temp;
int qtnt;

for (int i = 0 ; i <= Student_Max; i++)
{
    StudentInfo[i].StudentLine1 = "Student Name";
    StudentInfo[i].StudentLine1 = YEAR;
    StudentInfo[i].StudentNo1 = -1;
    StudentInfo[i].StudentLine2 = "Student Name";
    StudentInfo[i].StudentLine2 = YEAR;
    StudentInfo[i].StudentNo2 = -1;

    if (qtnt = (Student_Max / 2)
    {
        int qtnt1 = qtnt;
        int qtnt2 = qtnt1 + qtnt;

        temp.Format("StudentName %d", i+1);

        if (i < qtnt1)
        {
            StudentInfo[i].StudentLine1 = (new CString(temp))[0];
            StudentInfo[i].StudentYear1 = STUDENTYEAR;
            StudentInfo[i].StudentNo1 = i;
        }
        else if (i < qtnt2)
        { 
            StudentInfo[i].StudentLine2 = (new CString(temp))[0];
            StudentInfo[i].StudentLine2 = STUDENTYEAR;
            StudentInfo[i].StudentNo2 = i;
        }
    }
}

1 个答案:

答案 0 :(得分:1)

这个怎么样?

for(int i = 0 ; i <= Student_Max; i++){
    StudentInfo[i].StudentLine1 = "Student Name";
    StudentInfo[i].StudentLine1 = YEAR;
    StudentInfo[i].StudentNo1   = -1;
    StudentInfo[i].StudentLine2 = "Student Name";
    StudentInfo[i].StudentLine2 = YEAR;
    StudentInfo[i].StudentNo2   = -1;


    if (qtnt = (Student_Max / 2)
    {
        int qtnt1 = qtnt;
        int qtnt2 = qtnt1 + qtnt;

    temp.Format("StudentName %d", i+1);

    if (i < qtnt1)
    {
        StudentInfo[i].StudentLine1 = (new CString(temp))[0];
        StudentInfo[i].StudentYear1 = STUDENTYEAR;
        StudentInfo[i].StudentNo1   = i;
    }

    else if (i < qtnt2)
    { 
-->        StudentInfo[i - qtnt1].StudentLine2 = (new CString(temp))[0];
-->        StudentInfo[i - qtnt1].StudentLine2 = STUDENTYEAR;
-->        StudentInfo[i - qtnt1].StudentNo2   = i;
    }
}

这仅适用于2列,您需要适当地重新学习StudentInfo []。