lamp

July 2009 - Posts

The params keyword, when a single argument is not enough
27 July 09 11:53 PM | Frederick.Chapleau | with no comments

When you don’t want to provide a fixed number of argument for a method, you can use the params modifier, that can handle a list of values of a single type, instead of requiring from the caller to build a list.

void UseParams(params int[] list)

-f.

ref.: http://msdn.microsoft.com/en-us/library/w5zay9db.aspx

Filed under:
Use always the same standard for exceptions and event
26 July 09 11:11 AM | Frederick.Chapleau | with no comments

e is not enough... usually handle event as an “e”, and exceptions as an “ex”

...sorry, it too obvious ;)

-f.

Filed under:
A new way to handle cleanup
25 July 09 09:31 PM | Frederick.Chapleau | with no comments

You should know about the try{}catch{} block. But did you know that you can use a try{}finally{} block?

So when an error is raised, you are sure that the statements in the finally block are executed.

-f.

Filed under:
Usage of the @
24 July 09 05:05 PM | Frederick.Chapleau | with no comments

In C#, when you have a string with slash in it, you must double it to have a result of only one, because of the escape code.

When starting a string with a @, you can’t insert escape code, but you do not have to double them.

-f.

Filed under:
The 3 Strike Method
23 July 09 11:40 AM | Frederick.Chapleau | with no comments

1. You write it, as good as you think it should be implemented.

2. You realize that it can be better, you can improve it.

3. The last time you touch it, after that it can only be worst.

-f.

Filed under:
Use the String.Format
22 July 09 08:22 AM | Frederick.Chapleau | with no comments

You can a string using a standard.Comparable to the sprintf C format...

-f.

ref.: http://msdn.microsoft.com/en-us/library/system.string.format(VS.71).aspx

Filed under:
Explicitly call Dispose
21 July 09 03:23 PM | Frederick.Chapleau | with no comments

Calling Dispose release resources immediately, that can be useful for big files, handles etc...

-f.

Filed under:
Improve your startup
20 July 09 11:21 PM | Frederick.Chapleau | with no comments

Use SGEN to generate the XML Generation assembly, it can be improved from milliseconds to minutes...

-f.

http://msdn.microsoft.com/en-us/library/bk3w6240(VS.80).aspx

Filed under:
JavaScript Timeout retention
19 July 09 04:22 PM | Frederick.Chapleau | with no comments

Timeout are used since… well… since the dynamic web exists. But the returned timeout variable (usally a number) can be used to stop them. A good hint is to always store it somewhere, so that you can easily cancel them later.

-f.

Filed under:
CSS Z-Index
18 July 09 07:19 PM | Frederick.Chapleau | with no comments

A great layout tips... Overlay!

The Zindex CSS property can priories the layout order. A kind of Bring Forward and Send to Back.

-f.

Filed under:
Output Cache on ASP.NET Page
17 July 09 08:33 AM | Frederick.Chapleau | with no comments

A really simple performance improvement is to enable page caching in ASP.Net.

An example OutputCache VaryByParams="none" Duration="60".

-f.

.ToArray()
16 July 09 07:11 PM | Frederick.Chapleau | with no comments

In opposition of a previous post, if you need to create a Array with unknow length, you can just create an ArrayList and call the ToArray() method on it.

-f.

Filed under:
Trace without Console.Write
15 July 09 04:13 PM | Frederick.Chapleau | with no comments

A better way to Trace without using Console.Write, is simply to use the Trace.Write, and using a ConsoleTraceListener.

This will automatically dump traces to the console.

-f.

Filed under:
Array On-the-fly Creation
14 July 09 12:51 PM | Frederick.Chapleau | with no comments

If you do not know it, you can create on-th-fly an array, without passing thru an Arraylist or other lists that as the .ToArray() method.

new object[] { item, item, item} // give you an array with 3 items.

-f.

Filed under:
Partial Methods to the rescue
13 July 09 10:25 PM | Frederick.Chapleau | with no comments

If you already know partial classes, you should take a look at partial method.

This is far from basic c# code, but can be useful in some cases.

-f.

ref.: http://community.bartdesmet.net/blogs/bart/archive/2007/07/28/c-3-0-partial-methods-what-why-and-how.aspx

Filed under:
More Posts Next page »