I am new to programming in C#. I guess it might be a very easy solution which I am not aware of .
Suppose I have a class file
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;
}
}
Now in aspx.cs file how do I add marks to the array declared?
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;
}
}
}
I need to dynamically add items to it at run time. How do I do that? Do I have to change the array to list array in the class file..Hope I am making some sense out of my question.Later I need to bind the marks to the gridview.
Please help!
Arrays have a fixed size – use a more flexible collection such as
List<T>, which will grow as you need it to.Eric Lippert has a good blog post about why arrays should be considered somewhat harmful.
Additionally: