Я хочу содержать мои данные в этой структуре:
Dictionary<string, Dictionary<string, List<double>>> carInfo =
new Dictionary<string, Dictionary<string, List<double>>>();
И я хочу разобрать это.
Я добавляю некоторые данные в этот словарь, например:
adder.addCarItem("brand1", "type1", 1000, 1);
adder.addCarItem("brand2", "type2", 1000, 1);
наконец-то я хочу вывести всю эту структуру как:
foreach(KeyValuePair<string, Dictionary<string, List<double>>> car in warehouse.GetCarInfo)
{
Console.WriteLine(car.Key);
foreach(var type in car.Value)
{
Console.WriteLine(type.Key);
for(int i = 0; i < type.Value.Count; i++)
{
Console.WriteLine(type.Value[i]);
}
}
}
и вывод
brand1
type1
type2
brand2
type1
type2
но я хочу вывести вот так
brand1
type1
1000
1
brand2
type2
1000
1
Как лучше всего реализовать этот синтаксический анализ для этой структуры? может кто-нибудь знает ...
Код, как добавить элементы в словарь
Dictionary<string, Dictionary<string, List<double>>> carInfo =
new Dictionary<string, Dictionary<string, List<double>>>();
Dictionary<string, List<double>> carType = new Dictionary<string, List<double>>();
List<double> countAndCost = new List<double>();
public void addCarItem(string carBrand, string brandType, double carsNumber, double carCost)
{
countAndCost.Add(carsNumber);
countAndCost.Add(carCost);
carType.Add(brandType, countAndCost);
carInfo.Add(carBrand,carType);
}