728x90
반응형
WPF & C# - List<string> 중복제거 ( Distinct() / string.Join ) |
MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <StackPanel Margin="10"> <TextBlock Text="List<string> 중복제거 Distinct()" FontWeight="Bold" FontSize="20" Margin="5"></TextBlock> <StackPanel Orientation="Horizontal" Margin="5"> <Button x:Name="btn" Height="50" Width="100" Content=" 난수발생 " Click="btn_Click"/> <Label x:Name="lbl01" /> </StackPanel> <StackPanel Orientation="Horizontal" Margin="5"> <Button x:Name="btn01" Height="50" Width="100" Content=" 정렬 " Click="btn01_Click"/> <Label x:Name="lbl02"/> </StackPanel> <StackPanel Orientation="Horizontal" Margin="5"> <Button x:Name="btn02" Height="50" Width="100" Content=" 중복제거 " Click="btn02_Click"/> <Label x:Name="lbl03"/> </StackPanel> </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 | List<string> lst = null; void AddData() { lst = new List<string>(); Random rand = new Random(); int result = 0; for (int i = 0; i < 15; i++ ) { result = rand.Next(1, 10); // 1에서 50까지 사이 랜덤 숫자 발생 lst.Add(result.ToString()); } } // 난수발생 private void btn_Click(object sender, RoutedEventArgs e) { AddData(); lbl01.Content = string.Join(", ", lst); } // 정렬 private void btn01_Click(object sender, RoutedEventArgs e) { lst.Sort(); lbl02.Content = string.Join(", ", lst); } // 중복제거 private void btn02_Click(object sender, RoutedEventArgs e) { IEnumerable<string> Data = lst.Distinct(); foreach (string str in Data) { lbl03.Content = string.Join(", ", Data); } } | cs |
728x90
반응형