Многомерный массив как на php - C#
Формулировка задачи:
Как сделать типа такого массива:
И обращатся можно было так:
На пхп так работает... А как на C# так же сделать, я знаю мой код выше неправильный, но покажите как правильно будет ???
string[] Arrik = {
"Array1"->"Name"->"Алексей",
"Array1"->"Age"->"13",
"Array1"->"City"->"Moscow",
};Arrik['Array1']['Name']; // вернет имя Arrik['Array1']['Age']; // вернет возраст Arrik['Array1']['City']; // вернет город
Решение задачи: «Многомерный массив как на php»
textual
Листинг программы
using System;
namespace n
{
struct TestStruct
{
public string name;
public int age;
public string city;
public TestStruct(string name, int age, string city) : this()
{
this.name = name;
this.age = age;
this.city = city;
}
public static TestStruct Add(string name, int age, string city)
{
return new TestStruct(name,age,city);
}
}
class Program
{
static void Main(string[] args)
{
TestStruct[] arr = new TestStruct[]
{
TestStruct.Add("Jack",18,"London"),
TestStruct.Add("Sam",22,"New-York"),
};
int age= arr[0].age;
Console.WriteLine(age);
}
}
}