본문 바로가기

Programing (프로그래밍)/WPF & C# (C Sharp)

WPF & C# - Dictionary 딕셔너리 사용법 ( 딕셔너리 / Int / String / Colors / 매칭변수 / key Value)

728x90
반응형


 WPF & C# - Dictionary 딕셔너리 사용법 ( 딕셔너리 / Int / String / Colors / 매칭변수 / key Value)



testDictionary.zip





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<intint> int_int = new Dictionary<intint>();
    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<stringint> str_int = new Dictionary<stringint>();
    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<stringstring> str_str = new Dictionary<stringstring>();
    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(2552552550);
    int_Color[5= Color.FromArgb(2550255255);
    int_Color[6= Color.FromArgb(2552550255);
    lbl.Content += "[int_Color] " + " 4 = " + int_Color[4+ "\n\n";
}
cs




728x90
반응형