C:\DATA\C#\BAT>Rensou Daisy => 72 Eliza => 78 Becky => 85 Alice => 95 Cindy => 100 |
前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
/*★ 連想配列 前田 稔 ★*/
using System;
using System.Collections.Generic;
using System.Linq;
class DictionaryTest
{ static void Main()
{ Dictionary<string, int> dic = new Dictionary<string, int>()
{ { "Becky", 85 },
{ "Daisy", 72 },
{ "Alice", 95 },
{ "Eliza", 78 },
{ "Cindy", 100 },
};
var sorted = dic.OrderBy((x) => x.Value); //昇順
foreach(var v in sorted)
{ Console.WriteLine(v.Key + " => " + v.Value); }
}
}
|
{ Dictionary<string, int> dic = new Dictionary<string, int>()
{ { "Becky", 85 },
{ "Daisy", 72 },
{ "Alice", 95 },
{ "Eliza", 78 },
{ "Cindy", 100 },
};
|
var sorted = dic.OrderBy((x) => x.Value); //昇順
foreach(var v in sorted)
{ Console.WriteLine(v.Key + " => " + v.Value); }
}
}
|
Daisy => 72 Eliza => 78 Becky => 85 Alice => 95 Cindy => 100 |
![]()
/*★ 連想配列 前田 稔 ★*/
using System;
using System.Collections.Generic;
using System.Linq;
class DictionaryTest
{ static void Main()
{ Dictionary<string, int> dic = new Dictionary<string, int>()
{ { "Becky", 85 },
{ "Daisy", 72 },
{ "Alice", 95 },
{ "Eliza", 78 },
{ "Cindy", 100 },
};
dic.Add("Key3", 30);
dic.Add("Key1", 10);
dic.Add("Key2", 20);
var sorted = dic.OrderByDescending((x) => x.Key); //降順
foreach(var v in sorted)
{ Console.WriteLine(v.Key + " => " + v.Value); }
}
}
|
dic.Add("Key3", 30);
dic.Add("Key1", 10);
dic.Add("Key2", 20);
|
var sorted = dic.OrderByDescending((x) => x.Key); //降順
|
foreach(var v in sorted)
{ Console.WriteLine(v.Key + " => " + v.Value); }
}
|
Key3 => 30 Key2 => 20 Key1 => 10 Eliza => 78 Daisy => 72 Cindy => 100 Becky => 85 Alice => 95 |
![]()