The .Net IComparer Interface - Part 4


Part one described the sample application user experience.

Part two explained the main form engineering of the C# solution.

Part three described the C# solution IComparer sort machinery.

Part four here will explain the C# solution data display form, and wrap up with a brief description of the differences between the C# and example applications.

Download the sample C# / software at the GitHub repository.


The btn_load click event method
of CSharp_Demo_App.cs assembles and formats the display text, placing the text in variable recipe_text. Then, it declares and initializes localTextForm1, a textForm1 class instance, at line 230. This method disables the CSharp_Demo_App button controls, passes the recipe_text value to localTextForm1, and finally shows localTextForm1. CSharp_Demo_App sets the localTextForm1 recipe_text property value to recipe_text at line 235.

At line 26

1. The textForm1 class
the textForm1 class load event adds and configures variable localRTB, a RichTextBox form control originally declared and initialized as a private class variable. At line 40, it places the line 21 recipe_text class property value in the localRTB text property. The Close button closes the form and returns focus to CSharp_Demo_App.

Past syntax and a few code differences, the and C# applications are almost the same. The ColumnSorter class and code-behind files avoid the namespace / partial class syntax of the C# code. Additionally, the code-behind files avoid the InitializeComponent() calls found in the C# versions. Beyond this and language syntax differences, these applications are almost exactly the same.

This article showed that the IComparer Interface makes it easy to offer flexible, dynamic sort features in Windows desktop applications. Developers can focus on the business rules and requirements - IComparer will do the hard work.