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.

Centering Fixed-width CSS Layout

<style type="text/css">
    #container{position:relative; margin:auto; width:760px;}
    #logo     {position:absolute; width:760px; left:0px;  top:0px}
    #nav      {position:absolute; width:200px; left:0px;  top:100px}
    #content  {position:absolute; width:400px; left:200px; top:100px}
    #link     {position:absolute; width:160px; left:600px;top:100px}
</style>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body style="margin-top:0px">
    <div id = "container">
        <div id = "content">this is the <em>CONTENT</em> part</div>
        <div id = "logo">this is the <em>LOGO</em> part</div>        
        <div id = "nav">this is the <em>NAV</em> part</div>        
        <div id = "link">this is the <em>LINK</em> part</div>
    </div>    
</body>
</html>

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"