I have an application that on start-up loads 10 List<myClass>
.
My work loads a little slow and I was thinking to use arrays instead of List<T>
.
My Code:
List<MyClass> objects = MyClass.Get();
foreach (MyClass c in objects)
{
comboBox.Items.Add(c.Text);
}
class MyClass
{
//some properties
public MyClass(string key)
{
//Database is another class for executing sql queries.
//GetString(int columnIndex, int rowIndex)
using (DataBase db = new DataBase())
{
db.Query = "SELECT ID FROM sampleTable WHERE ID= @param";
db.Parameters.Add("param", SqlDbType.NVarChar, 100, key);
Name = db.GetString(0, 0);
}
}
public static List<MyClass> Get()
{
using (Database db = new Database())
{
db.Query = "SELECT ID FROM sampleTable ORDER BY sampleTextField";
int c = db.GetRowCount();
List<MyClass> result = new List<MyClass>();
for (int i = 0; i < c; i++)
{
result.Add(new MyClass(db.GetString(0, i)));
}
return result;
}
}
}
Is it a good idea to use arrays?
Please feel free to offer me any idea for speeding up this code.