Browse by Tags
All Tags »
LINQ »
C# »
CSharp (
RSS)
If you are doing any type of statistical analysis, you probably need to calculate mean, median and mode. There are lots of places on the Web you can find the calculations. This post is different than most in that it uses LINQ and Lambda expressions. Mean...
There are often cases where you need to group on multiple properties and potentially sum on others. This post details how to group and sum on multiple properties using lambda expressions. This example uses an Invoice class, since that provides many opportunities...
In this prior post , I demonstrated how to find a node in an XML string. In this post, I expand on that topic to find a set of nodes. You can then process those nodes as needed in your application. In this example, the set of nodes are displayed in a...
If you retrieve data into a DataTable, it is easy to bind it to a ComboBox. And before Linq, you would filter the DataTable using a DataView. But with Linq, you have some easy to use features for filtering the contents of your ComboBox. First, here is...
A common requirement with an XML file is to find a particular node. If you are targeting the .NET framework 3.5 or higher, you can find the node using Linq to XML or by using Lambda expressions. As with many of my prior XML examples, the XML string is...
If you are using XML in a WinForms application you may find the need to display the XML data in a DataGridView. Let's take this XML: <states> <state name="California"> ...
In this prior post , I detailed how to build lists of things using a generic List<T>. Once you have a list, you may need to find items in the list. There are several ways to accomplish this, but using lambda expressions is the most concise. [To...
The Enumerable class is new in .NET 3.5 and is part of the System.Linq namespace. It provides a set of static methods that allow you to query any object that implements IEnumerable, basically meaning any object that supports a for/each. This post focuses...
I have an XML string as follows: <States> <State name="Wisconsin"> <Regions> <Region name="Milwaukee"> <Area...
Another use of anonymous types is for processing directories or files. For example, your application needs to collect a set of files and then process them based on a subset of the file properties. [To begin with an overview of anonymous types, start here...
The last several posts have provided examples of using anonymous types. This post backs up a little and provides an introduction if you are not already familiar with anonymous types. If you are familiar with anonymous types and are looking for more...
Similar to my prior post here that details how to use anonymous types to display word counts, this post details how to track information on the physical lines that contain each word. Again, this specific task is more like a homework assignment than a...
This may be more of a homework assignment for a programming class than something you would do in your applications, but it is a good example of using anonymous types, which are new in .Net 3.5 in both VB and C#. [To begin with an overview of anonymous...
Some of the collections in the Microsoft Office object models implement IEnumerable. The IEnumerable interface provides the ability to perform a for/each against the collection. With .NET 3.5, a Cast extension method of IEnumerable allows you to work...
If you are using Visual Studio 2008 (.NET Framework 3.5) or newer, you can leverage inferred typing. Inferred typing allows the compiler to infer your data types instead of you having to explicitly define the type. Variables that use inferred typing are...
Last night, my husband (who is also a .NET developer) asked me about sorting a DataTable by user-defined columns. (Yes, we are a pretty exciting couple!) Most developers that work with DataTables know how to sort the DataTable using a DataView.Sort. If...
This entry details the implementation of the ZodiacSigns class from this example in C#: public class ZodiacSigns : List<ZodiacSign> { } Constructor The following is the constructor defined in the ZodiacSigns class: public ZodiacSigns() { ...
Defining a list of integers in your code involves lots of tedious typing. In VB, you can’t do this: 'Dim numberList As new List(Of Integer) = {1, 2, 3, 4, 5, 6, 7, 8, 9} So you have to either add numbers to the list manually, or create an array, which...