Skip to content

Category Archives: Code

All things related to code and its development.

Make aliases an option

26-Nov-09

Do you prefer int or Int32? How about string or String? Some developers have strong preferences, others don’t care. Personally, I prefer to use the actual CLR type names (in other words I prefer Int32 and String) and since I do, I feel as though I am a second-class citizen.

Interestingly enough, it [...]

Smarter type inference with C# 4

03-Nov-09

Here is a new addition to the C# language in version 4 that doesn’t seem to be getting much attention. The type inference algorithm has become smarter and for the first time we are able to infer generic type arguments from the return types of methods in certain cases.

Consider this example that compiles in [...]

You don’t always need a lambda expression

01-Nov-09

C# 3 gave us the lambda expression and ever since we have been using them to create abstract representations of terse, anonymous functions.

While expressive and helpful, they are not always needed. Consider this example:

using System; using System.Collections.Generic; class Example { static void Main() { [...]

All types are not compared equally

29-Oct-09

Here is a bit of a quiz: What does this program print?

using System; using System.Collections.Generic; class Person { public String Name { get; set; } } class Example { static void Main() { var people = new List<Person> { [...]

Know your framework

13-Oct-09

What is wrong with the following program?

using System; using System.Net; using System.IO; using System.Text; class Example { static void Main() { Console.WriteLine( getWebPage(“http://example.com”)); } static String getWebPage(String url) [...]

ASP.NET, JavaScript, and the mangled ID

08-Oct-09

Many times I see folks struggling with a problem like this:

I really want to get at an ASP.NET control with JavaScript but once the control has rendered, the ID of the control gets mangled to look something like ctl00_Content_foo_bar. How do I go about working with this control in JavaScript since the ID [...]

Two casts are not better than one

26-Sep-09

C# has an interesting operator know as “is“. The is operator is used for execution-time type checking. It is a binary operator that returns a Boolean indicating whether or not the instance in question is in fact of the type specified as the second operand.

Here is an example:

using System; class Example { [...]