Answer the question
In order to leave comments, you need to log in
How to populate a DataGridView with elements of an array of class objects?
string[] database = File.ReadAllLines("database.txt");
int len = database.Count(); // Количество строк
auto[] car = new auto[len];
for (int i = 0; i < len; i++) // Создание элементов массива объектов
{
string line = database[i];
string[] linemas = line.Split('|');
int id = Convert.ToInt32(linemas[0]);
car[i] = new auto(id);
}
class auto
{
public string carname;
public int i;
public double price;
public string address;
public auto(int _id)
{
i = _id - 1; // Индексация в файле начинается с 1
string[] database = File.ReadAllLines("database.txt");
string line = database[i]; // Строка по айди
string[] linemas = line.Split('|'); // Разделили строку
carname = linemas[1];
price = Convert.ToDouble(linemas[2]);
address = linemas[3];
}
public double CalcRealPrice(double _multiplier)
{
return price *= _multiplier;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question