Windows Forms: How to Read text file and Sort list in C#
By FoxLearn 7/4/2017 9:55:52 PM 6.8K
How to read text (*.txt) file and sort list/array data in C#
Step 1: Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "ReadTextFileAndSort" and then click OK
Step 2: Design your form as below
Step 3: Add code to button click event handler as below
private void btnOpen_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Text Documents(*.txt)|*.txt", ValidateNames = true, Multiselect = false }) { if (ofd.ShowDialog() == DialogResult.OK) { //Read text file string[] lines = System.IO.File.ReadAllLines(ofd.FileName); List<int> list = new List<int>(); foreach (string s in lines) { list.Add(Convert.ToInt32(s)); listReadFile.Items.Add(s); } //Sort list list.Sort(); foreach (int x in list) listSort.Items.Add(x); } } }
VIDEO TUTORIALS
- How to Send and Receive email in Microsoft Outlook using C#
- How to Print Windows Form in C#
- How to Use Form Load and Button click Event in C#
- How to use Advanced Filter DataGridView in C#
- How to use TagListControl in C#
- How to use Error Provider in C#
- How to Drag and Drop controls in C#
- How to Create a Random Password Generator in C#
Categories
Popular Posts
How to Download Chromedriver for Selenium
08/29/2024
C# Tutorial
07/20/2024
How to Download Microsoft SQL Server
06/22/2024
What is ARM architecture?
04/01/2024