C# Anonymous Methods & The Action Object

Two interesting additions to the 2.0 C# language are the Action<> object, and anonymous methods. The Action<> object lets you specify an action to be performed on an object. And the anonymous method lets you specify a method with no body (thus... the anonymity). The Action Object public delegate void Action<T>(T obj); The Action object is used to... Continue Reading →

#if

When the C# compiler encounters an #if directive, followed eventually by an #endif directive, it will compile the code between the directives only if the specified symbol is defined. Unlike C and C++, you cannot assign a numeric value to a symbol; the #if statement in C# is Boolean and only tests whether the symbol has... Continue Reading →

var

Beginning in Visual C# 3.0, variables that are declared at method scope can have an implicit type var. An implicitly typed local variable is strongly typed just as if you had declared the type yourself, but the compiler determines the type. The following two declarations of i are functionally equivalent: Beginning in Visual C# 3.0,... Continue Reading →

Using Types from Other Namespaces

n order to use a class that isn’t defined in one of the WPF namespaces, you need to map the .NET namespace to an XML namespace. XAML has a special syntax for doing this, which looks like this: xmlns:Prefix=”clr-namespace:Namespace;assembly=AssemblyName” Typically, you’ll place this namespace mapping in the root element of your XAML document, right after... Continue Reading →

Lambda Expressions

A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types. All lambda expressions use the lambda operator =>, which is read as "goes to". The left side of the lambda operator specifies the input parameters (if any) and the right side holds the... Continue Reading →

Auto-Implemented Prop

In C# 3.0 and later, auto-implemented properties make property-declaration more concise when no additional logic is required in the property accessors. They also enable client code to create objects. When you declare a property as shown in the following example, the compiler creates a private, anonymous backing field can only be accessed through the property's get... Continue Reading →

Benchmark Programs in C#

Problem. You are wondering if the C# programming language is fast. You question whether it is worth benchmarking programming languages. What else can you learn from careful benchmarks? Solution. Here's a benchmarking overview using the C# programming language that touches on some important things about benchmarking. ::: Benchmarking tip ::: Use the programs here to perform... Continue Reading →

Create a website or blog at WordPress.com

Up ↑