Category Archives: LINQ

Use PLINQ to select prime numbers from an array in C#

The example Use PLINQ to select even numbers from an array in C# uses PLINQ (Parallel LINQ) to find the even numbers in an array of random values. This example uses a similar technique to do something slightly more interesting: … Continue reading

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

Use PLINQ to select even numbers from an array in C#

This example is really a demonstration of PLINQ, since you probably won’t need to use this technique to find even numbers. (If you do need to generate even numbers, it’s a lot faster and easier to simply pick random numbers … Continue reading

Posted in LINQ, performance | Tagged , , , , , , , , , , | 3 Comments

Determine whether two lists contain the same sequences of objects in different orders in C#

The SequenceEqual method determines whether two IEnumerable sequences contain the same objects in the same order. There is a simple way to determine whether the lists contain the same objects in different orders: sort the objects and then call SequenceEqual. … Continue reading

Posted in LINQ, lists, miscellany, OOP | Tagged , , , , , , , , , , , , , | Leave a comment

Use LINQ with an embedded lambda expression to find prime numbers in C# (Part 3 of 3)

The example Use more efficient LINQ to find prime numbers in C# (Part 2 of 3) uses a LINQ query to find prime numbers. It creates a delegate variable named IsOddPrime referring to a lambda expression and uses it to … Continue reading

Posted in algorithms, LINQ, mathematics | Tagged , , , , , , , , , , | 4 Comments

Use more efficient LINQ to find prime numbers in C# (Part 2 of 3)

The previous post showed how you can use LINQ to find prime numbers. For every number between 1 and a maximum, the LINQ query called the IsPrime method to see if the number should be part of the selection. That … Continue reading

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

Use LINQ to find prime numbers in C# (Part 1 of 3)

This example uses LINQ to find prime numbers between 1 and a maximum value that you enter. It defines the following IsPrime method to determine whether a number is prime. // Return true if the number is prime. private bool … Continue reading

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

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