728x90
반응형
WPF & C# - Dictionary 딕셔너리 사용법 ( 딕셔너리 / Int / String / Colors / 매칭변수 / key Value) |
MainWindow.xaml.cs
1 2 3 4 | <StackPanel HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"> <Button x:Name="btn" Content="Dictionary / 딕셔너리" Height="30" Click="btn_Click"/> <Label x:Name="lbl" FontSize="16"></Label> </StackPanel> | cs |
MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | private void btn_Click(object sender, RoutedEventArgs e) { lbl.Content = ""; // Dictionary<int, int> Dictionary<int, int> int_int = new Dictionary<int, int>(); int_int[1] = 035; int_int[3] = 196; int_int[5] = 299; lbl.Content += "[int_int] " + " 5 = " + int_int[5] + "\n\n"; // Dictionary<string, int> Dictionary<string, int> str_int = new Dictionary<string, int>(); str_int["A"] = 9; str_int["B"] = 8; str_int["C"] = 7; lbl.Content += "[str_int] " + " A = " + str_int["A"] + "\n\n"; // Dictionary<string, string> Dictionary<string, string> str_str = new Dictionary<string, string>(); str_str["D"] = "day"; str_str["E"] = "eraser"; str_str["F"] = "fly"; lbl.Content += "[str_str] " + " E = " + str_str["E"] + "\n\n"; // Dictionary<Color, int> Dictionary<Color, int> Color_int = new Dictionary<Color, int>(); Color_int[Colors.Red] = 1; Color_int[Colors.Blue] = 2; Color_int[Colors.Black] = 3; lbl.Content += "[Color_int] " + " Colors.Red = " + Color_int[Colors.Red] + "\n\n"; // Dictionary<int, Color> Dictionary<int, Color> int_Color = new Dictionary<int, Color>(); int_Color[4] = Color.FromArgb(255, 255, 255, 0); int_Color[5] = Color.FromArgb(255, 0, 255, 255); int_Color[6] = Color.FromArgb(255, 255, 0, 255); lbl.Content += "[int_Color] " + " 4 = " + int_Color[4] + "\n\n"; } | cs |
728x90
반응형