Category Archives: LINQ

Use LINQ to select words of certain lengths from a file in C#

This example uses LINQ to read a file, remove unwanted characters, select words of a specified length, and save the result in a new file. Recently I needed a big word list so I searched around for public domain dictionaries. … Continue reading

Posted in algorithms, files, LINQ | Tagged , , , , , , , , , , , | 2 Comments

Sort words by letter count in C#

This example sorts words by letter count. It counts the number of distinct letters in a list of words and displays the words and their counts sorted by the counts. The program is remarkably simple. The following code shows how … Continue reading

Posted in algorithms, LINQ, mathematics | Tagged , , , , , , , , , , , | Leave a comment

Convert latitudes and longitudes into distances on the globe in C#

This example shows how you can convert latitudes and longitudes into distances on the globe. The formulas for performing those calculations is interesting but the program is also interesting for the ways it uses LINQ. The program stores information about … Continue reading

Posted in algorithms, LINQ, mathematics | Tagged , , , , , , , , , , , , | 1 Comment

List colors in WPF and C#

This example shows how to list colors and display color samples in a WPF ListBox. To build the list, the example demonstrates reflection, LINQ, and XAML data templates. The program uses the following XAML code to define the ListBox that … Continue reading

Posted in drawing, enums, graphics, LINQ, reflection, wpf, XAML | Tagged , , , , , , , , , , , , , , , , , , , , , , | Leave a comment

List unique words in a text file in C#

This example uses regular expressions and LINQ to list the unique words contained in a text file in C#. When you enter the name of a file and click List Words, the following code executes. // List the words in … Continue reading

Posted in files, LINQ, regular expressions | Tagged , , , , , , , , , , | 1 Comment

Compare LINQ speeds for different approaches in C#

This example compares LINQ speeds while using LINQ in various ways. To find the minimum and maximum X values in a List<Point>, the example Use LINQ to find a bounding box for a list of PointF in C# defines a … Continue reading

Posted in LINQ, performance | Tagged , , , , , , , | Leave a comment

Use LINQ to find a bounding box for a list of PointF in C#

This example shows how to use LINQ to find a bounding box for a list of PointF. When you click on the program’s PictureBox, it adds points to the list and shows the bounding box. The following method finds the … Continue reading

Posted in graphics, LINQ | Tagged , , , , , , , , , , , | Leave a comment

Use LINQ Min, Max, and Average extension methods in C#

This example shows how to use LINQ Min, Max, and Average extension methods to get the minimum, maximum, and average values from an array. In order to support LINQ, Microsoft added those extension methods and others. LINQ includes several useful … Continue reading

Posted in extension methods, LINQ, mathematics | Tagged , , , , , , , , , , , , | Leave a comment

Make a program display its own binary code in three ways in C#

I recently wanted to put a chunk of binary code in a book to show what code really looks like to the computer, so I wrote this program. This isn’t a spectacularly useful program, but it does demonstrate a few … Continue reading

Posted in LINQ, programs, strings | Tagged , , , , , , , , , , , | Leave a comment

Use LINQ to list files and file sizes in a directory in C#

When you enter a directory name and click the List Files button, the following code lists files and file sizes in the directory you entered in the text box. // List the files in the selected directory and their sizes. … Continue reading

Posted in files, LINQ | Tagged , , , , , , , , , , , , , | Leave a comment