IntelliSenseは効きませんが、dynamicを使用するのはいかがでしょうか。
lang
1var dic = new Dictionary<string, dynamic>();
2dic.Add("name", new List<string>{ "apple", "orange", "grape" });
3dic.Add("price", new List<int>{ 200, 300, 150 });
4
5dic["name"].Add("banana");
6dic["price"].Add(400);
使用用途にもよると思いますが、c#においては他に、
- Dictionary<string, object>を使用し、キャストする方法
lang
1var dic = new Dictionary<string, object>();
2dic.Add("name", new List<string> { "apple", "orange", "grape" });
3dic.Add("price", new List<int> { 200, 300, 150 });
4
5((List<string>)dic["name"]).Add("banana");
6((List<int>)dic["price"]).Add(400);
- Dictionary<string, int>を使用する方法
lang
1var dic = new Dictionary<string, int>();
2dic.Add("apple", 200);
3dic.Add("orange", 300);
4dic.Add("grape", 150);
- nameとpriceをメンバーに持つクラスを定義してList<T>で管理する方法
lang
1class Fruit
2{
3 public string Name { get; set; }
4 public int Price { get; set; }
5}
lang
1var list = new List<Fruit>();
2list.Add(new Fruit { Name = "apple", Price = 200 });
3list.Add(new Fruit { Name = "orange", Price = 300 });
4list.Add(new Fruit { Name = "grape", Price = 150 });
等があると思います。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2016/05/17 08:09