Archive | C# Language RSS feed for this section

C# Destructor

As C# has an inbuilt garbage collection it is not necessary to explicitly destroy your objects. However, for objects which control unmanaged resources, these resources need to be explicitly freed when they are no longer require. In C#, implicit control over unmanaged resources is provided by a destructor, which can be called by the garbage [...]

Read more

C# 4.0 – Covariance and Contravariance of Generics

Covariance allows casting of generic types to the base types, for example, IEnumerable<X> will be implicitly convertible an IEnumerable<Y> if X can implicitly be converted to Y. // List of strings IList<string> stringList = new List<string>(); // We can convert it to an Enumerable collection IEnumerable<object> Obj= strings; For this purpose IEnumerable is marked with [...]

Read more

C# 4.0 – Named Parameters

C# 4.0 introduces named parameters which is primarily for code readability or for use with optional parameters.Named parameters free developers from the requirement to remember or to look up the order of parameters in the method’s signature. The parameter for each argument can be specified by providing the parameter name. For example, a function which [...]

Read more

C# 4.0 – Optional Parameters

New with C# 4.0 are optional parameters which have been offered in VB for some time. Optional Parameters can be used as an alternative to overloading methods. For example private string nameMethod(string firstName, string secondName = “Obama”, int age = 49) { return firstName + ” ” + secondName; } The first parameter is a [...]

Read more

C# 4.0 – Dynamic Lookup

C# 4.0 introduce Dynamic Lookup to the C# feature set. Dynamic Lookup is the ability to resolve names in a program at runtime instead of compile time. VB 2008 already includes this feature which is sometime referred to as Late Binding. Dynamic Lookup can be used for Office automation or COM Interop scenarios, consuming types [...]

Read more

C# – Understanding The NET Garbage Collector

A key pillar of the .NET framework is the managed code environment in which an in-built garbage collector automatically handles the tasks related to disposing of unused objects to free up memory. While the process is automatic there are a number of factors that you need to be aware of that can make the process [...]

Read more

C# – Best Practices For Writing High Performance Code

With faster processors and memory being almost free programmers are increasingly tempted to program for convenience and not performance. I recently had to write an application where performance was paramount and here are my top ten tips for writing high performance C# code : Avoid boxing and unboxing Boxing/unboxing enables value types to be treated [...]

Read more

LINQ Using C# – LINQ Operators

LINQ (Language INtegrated Query) was introduced with of C# 3.0 and .NET Framework 3.5. LINQ enables developers to write structured type-safe queries over local object collections and remote data sources. In essence it is  SQL for C#. LINQ allows for querying over any collection which implements IEnumerable<> (including arrays, lists, XML DOM, remote data objects [...]

Read more

C# Structs – Introduction

A Struct  is very similar to a Class,  however whereas a Class is a reference type  a Struct is a value type. Also, Classes support inheritance whereas Structs do not. In practice Structs are a lightweight class which are often used for numeric types. As they are a value type, each instance does not require [...]

Read more

C# Chain of Responsibility Pattern

Introduction This article shows a how to make a custom Wizard control using Chain of Responsibility Pattern which passes and returns data between each step. This sample creates a wizard control through windows form. Every step is responsible for its own validation and responsibility is break on each step rather then a single form .Previously [...]

Read more