728x90
반응형
WPF & C# - 정렬 ( 확장 정렬 ) |
MainWindow.xaml.cs
1 2 3 4 5 | <StackPanel Margin="10"> <TextBlock Text="정렬 / 확장정렬" FontWeight="Bold" FontSize="24"></TextBlock> <Button x:Name="btn" Height="30" Click="btn_Click"></Button> <Label x:Name="lbl"></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 | namespace testSort { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } public string PartName { get; set; } public int PartId { get; set; } private void btn_Click(object sender, RoutedEventArgs e) { Data[] pets = { new Data { Name="Barley", Age=8 }, new Data { Name="Boots", Age=4 }, new Data { Name="Whiskers", Age=1 } }; IEnumerable<Data> query = pets.OrderBy(pet => pet.Name); lbl.Content = ""; foreach (Data data in query) { lbl.Content += data.Name + " - " + data.Age + "\n"; } } } class Data { public string Name { get; set; } public int Age { get; set; } } } | cs |
728x90
반응형