Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Tuesday, 28 June 2011

Sort C# Code Structure In Visual Studio 2010 With CodeSorter

One of the most tiring task you might have to perform over source code files everyday is code sorting. Since there aren’t any set conditions which one can instantly apply over source code file to make it look tidy and clean, users have to manually sort the code structure according to their requirements. If you’re looking for a relatively easy way to sort your C# code in Visual Studio 2010, you can try out CodeSorter to specify code sorting conditions, so that they can be applied with a single click over all the code files. The add-in only works with C# project files and may disturb code structure of other languages. The add-in has a host of different code sorting conditions which can be customized in numerous ways. It was developed to sort source code files by different conditions such as, names, types; including, class, struct, method, virtual modifiers; virtual overide, new, etc.


Thursday, 23 June 2011

Extention method for IComparable


Hi friends,
 C# 3.0 gives great feature of extension method. so i keep playing with this. today  I would like to show you something interesting way to use that extension method. This time it's extending IComparable<T>. The API signature for IComparable<T> has been around since the birth of  C language . If the left is less than the right, return something less than 0, if left is greater than right, return something greater than 0, and if they are equivalent, return 0. Well, its readability leaves a bit to be desired.

Monday, 20 June 2011

As Operator in C#



The as operator is used to perform certain types of conversions between compatible reference types. "As" Operator is also known as a safe cast. What is does is it attempts to cast from one type to another and if the cast fails it returns null instead of throwing an InvalidCastException.


As-casting is equivalent to the following expression except that expression is evaluated only one time.

expression is type ? (type)expression : (type)null