我是C#編程新手。我想這可能是一個非常簡單的解決方案,我不知道。將項添加到類中的數組
假設我有一個類文件
using System;
using System.Collections.Generic;
namespace sharepointproject1
{
public partial class School
{
public students[] students { get; set; }
}
public partial class student
{
public marks[] marks;
public extraactivites[] extraactivities;
}
public partial class marks
{
public int m1 { get; set; }
public int m2 { get; set; }
}
public partial class extraactivities
{
public decimal m5;
public decimal m6;
}
}
現在aspx.cs文件如何添加標記到數組聲明?
namespace sharepointproject1
{
public partial class testing : usercontrol
{
School school = new school();
protected void Page_Load(object sender, EventArgs e)
{
school.students[0].marks[0].mark1 = 45;
}
}
}
我需要在運行時動態添加項目。我怎麼做?我是否需要將數組更改爲類文件中的列表數組?希望我的問題能夠理解一些。後來我需要將這些標記綁定到gridview。
請幫忙!
我建議['System.Collections.Generic.List'](http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx)。或者建立自己的['System.Collections.CollectionBase'](http://msdn.microsoft.com/en-us/library/system.collections.collectionbase.aspx)對象。 –
2011-03-17 17:30:17