MVP Articles for C# and Visual Basic

MVP Articles for C# and Visual Basic

This page contains articles written by Microsoft MVPs on C#, Visual Basic, and related technologies.

Quick List of Articles Found Below

Adapting Task Asynchronous Programming Methods to Existing Interface Contracts
Implementing Dynamic Interfaces
Async Programming in Visual Studio 2010
An Async Primer
When Dynamic Meets Nullable
Tuples, Anonymous Types, and Concrete Types
System Collections Generic SortedSet
Type Inference
Understanding Delegates
Mixing LINQ Providers and LINQ to Objects
Use Optional Parameters to Minimize Method Overloads
Create Mixins with Interfaces and Extension Methods
Calculating with Infinite Sequences in C#
Custom Iterators
Introduction to Nullables
Named Parameters
Back to Basics: Tips for Greater Developer Productivity
LINQ and Productivity
Allocation of Disposable Members
Local Type Inference, Anonymous Types, and Var
Justification for Names and Optional Parameters
There Be Dragons

 

Articles with Summaries


Adapting Task Asynchronous Programming Methods to Existing Interface Contracts
The Task Asynchronous Programming model (TAP) provides a standard way to write async methods and make them testable. Tests can await async methods that return Task or Task. That ensures that assertions are not tested before the actions have completed. But some existing idioms we need to support do not allow us to follow the TAP model. These APIs mandate a different signature. This article shows techniques to write testable async code in a very common scenario where following the TAP model is difficult. You’ll be able to extend these techniques to other APIs where you need async methods that follow older conventions and aren’t TAP compliant. You'll be able to write testable async methods in any scenario.
Download PDF

 

Implementing Dynamic Interfaces
One great advantage of dynamic programming is the ability to build types whose public interfaces change at runtime based on how you use these types. C# provides that ability through dynamic, the System.Dynamic.DynamicObject class, and the System.Dynamic.IDynamicMetaObjectProvider interface. While DynamicObject is trivial to use, sometimes you need full control on the behaviors of getting a member, setting a member, or invoking a member. This article focuses on how to implement IDynamicMetaObjectProvider.
Download PDF

 

Async Programming in Visual Studio 2010
Regarding async language and library features for asynchronous programming, how do you structure your current production codebases to support asynchronous operations while preparing to use C#’s new async features? This article discusses how you can use language features and libraries to support asynchronous programming so that when you move your legacy systems to the new async features, it will be easier and quicker to do so. You’ll want to adopt the new language features as soon as you can; the new features greatly improve the experience.
Download PDF

 

An Async Primer
Asynchronous methods mean that your methods don’t always return complete results synchronously. They may return the promise of results at some future moment. Programming with future results changes the way you write code in profound ways. This article provides an overview of the async features in C# 5 and discusses some of the ways you should change your regular programing habits to take advantage of async programming features.
The article walks you through the tasks to convert a small WPF application from a synchronous model to an asynchronous model of execution.
Download PDF

 

When Dynamic Meets Nullable
This column discusses interplay between the rules for the dynamic type and the rules for nullable types. This interplay caused quite a bit of confusion and extra work on a large app because the team did not have a complete understanding of how these different parts of the language interact.
Download PDF

 

Tuples, Anonymous Types, and Concrete Types
The release of .NET Framework 4.0 adds Tuples to the base class library. One challenge for C# developers is that Tuples serve similar purposes to Anonymous Types. This article discusses when to use these types and some situations when you should avoid them in favor of declaring a class.
Download PDF

 

System Collections Generic SortedSet
The .NET 4.0 library includes an additional collection class: The SortedSet. At first glance, it doesn’t seem to provide anything new. This article explains how to choose which collection type to use and how the SortedSet stores its objects.
Download PDF

 

Type Inference
This article is about one line of code that doesn’t compile:
var lambda = x => x.M();
That line generates CS0815: “Cannot assign lambda expression to implicitly typed local variable.” Why doesn’t the C# language allow this, and what are the rules that govern type inference for implicitly typed local variables and lambda expressions?
Download PDF

 

Understanding Delegates
Questions about delegates are common, especially around the error message CS1660, “Could not convert lambda expression type to type System.Delegate because it is not a delegate type.” This article explains this error with an example from WPF code and what you can do about it.
Download PDF

 

Mixing LINQ Providers and LINQ to Object
This article discusses the differences between IEnumerable<T> and IQueryable<T>, explaining many of the terms you’ll see in literature about LINQ providers. LINQ to Objects is built on IEnumerable<T>. Any sequence that implements IEnumerable<T> can act as a LINQ data source. When a data source provides its own native query language, developers may create a LINQ provider to leverage that language. A LINQ provider translates LINQ queries into specific API calls against a data source.
Download PDF

 

Use Optional Parameters to Minimize Method Overloads
Named parameters work with optional parameters to limit the noisiness around many APIs, especially COM APIs for Microsoft Office. Changing the name of a public parameter could break calling code. That means you should avoid using named arguments in many situations. This article offers guidance on named parameters.
Download PDF

 

Create Mixins with Interfaces and Extension Methods
Mixins are small utility classes that define useful functionality that usually becomes part of another class. In C++, you create these mixin classes using regular class definitions, and larger classes that needed the mixin behavior would simply inherit from the mixin, in addition to any base classes the larger class needed. Because the .NET Framework does not support multiple inheritance, you typically use interfaces to define mixins. That works, but it’s not as powerful since you don’t inherit implementation. By creating extension methods using the interface, you can inject many more methods into the public definition of the interface, without forcing every developer to re-create those methods whenever he or she implements that interface.
Download PDF

 

Calculating with Infinite Sequences in C#
This article shows how to implement a Lazy list using IEnumerable and how you can use LINQ with infinite lists. An example shows using these techniques to implement the Mandelbrot set.
Download PDF

 

Custom Iterators
This article discusses custom iterators, predicates, and generic methods. You can combine these three techniques to create small building blocks that plug together in a variety of ways to solve everyday development problems. Once you can recognize when to apply this pattern, you will be able to create a large number of reusable building blocks.
Download PDF

 

Introduction to Nullables
A core principle for a value type is that it always has valid contents; the variable holding a value type is never null. For each value type T there is a corresponding type T?, whose domain of values includes null. For example, a variable of type int? can hold any 32 bit integer or null.
Download PDF

 

Named Parameters
This article discusses C# named and optional parameters and explains some of the subtle language design decisions that allow these features to fit into the language so well.
Download PDF

 

Back to Basics: Tips for Greater Developer Productivity
Visual Studio 2010 contains many features that enable very rich customization. For many developers, creating a new project means running one of the Visual Studio wizards. There are many things to like about wizards. However, in some cases, you want to change what the wizard does. This article discusses how Visual Studio executes project and new item wizards, how to modify existing templates, and how to create new item and project templates for your needs or coding guidelines.
Download PDF

 

LINQ and Productivity
LINQ enables writing algorithms that are easier to read, maintain, and extend. A reasonable investment in learning the functionality pays off heavily in programmer productivity, both for you, and the rest of your team that will read your code and extend it in the future. This article uses versions of a program to illustrate readability and expressiveness of LINQ.
Download PDF

 

Allocation of Disposable Members
Object lifetimes continue to cause developers confusion. The .NET Framework, like all garbage collected environments, simplifies the task of managing object ownership and object lifetime. Implementing the Dispose pattern handles those cases where an object owns resources that must be freed. This article discusses the situation when an object that allocates disposable objects encounters problems in its constructor and how to handle the situation.
Download PDF

 

Local Type Inference, Anonymous Types, and Var
This article discusses type inference from anonymous types to the ‘var’ declaration.
Download PDF

 

Justification for Names and Optional Parameters
Multiple languages demonstrate that named and optional parameters are useful, just like rest parameters. They are particularly useful when you have a very large number of parameters. The COM based Office APIs are the obvious example. This article discuss problems that can arise as you introduce the interaction between optional parameters and method overloads. Named and optional parameters constrain future component releases. You’ll learn how to best avoid these pitfalls in your own code.
Download PDF

 

There Be Dragons
Declarative programs specify what you want, and imperative programs specify how to do something. This article discusses mixing these concepts incorrectly and the serious problems that arise from bad mixing.
Download PDF
Sort by: Published Date | Most Recent | Most Useful
Comments
Page 1 of 1 (2 items)