When to use “is” and when to use “as” in C#

The is operator accepts an object on the left hand side and a type on the right. It returns true if the run-time type of the object on the left is compatible with the type on the right. Always use is before making the type cast.
The as actually cast the type on the left to the type on the right, null will be returned if the conversion fails.

  1. as is preferred, because it is more efficient (the conversion is already done with the as operator.
  2. For value-type variables, like int, char you can only use is to convert from one type to another.

C# Tricks

#region
… your code here inside a collapsible region.
#endregion

Save code in the toolbox, and use them later on.
Drag the selected lines of code into the General tab of the toolbox and drop them.

Ternary operator : ?

bool informal = true;
string name =informal : "Chuck" ? "Charles";  // Returns "Chuck"

PWSK- Handler.ashx

The Handler.ashx is used to dynamically return a image from a query string. Http handler is similar to regular web form, only faster (~10%, compare with web form) with less functionality.
IsReusable property is usually set to be true to reduce memory footprint and improve performance.
In the sample application pictures are taken from a database. If one prefer to use file system instead then the handler can be changed to.
HttpResponse r = context.Response;
r.ContentType = "image/png";
r.WriteFile("Logo1.png");