-
-
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
-
-
e is not enough... usually handle event as an “e”, and exceptions as an “ex”
...sorry, it too obvious ;)
-f.
-
-
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.
-
-
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.
-
-
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.
-
-
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
-
-
Calling Dispose release resources immediately, that can be useful for big files, handles etc...
-f.
-
-
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
-
-
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.
-
-
A great layout tips... Overlay!
The Zindex CSS property can priories the layout order. A kind of Bring Forward and Send to Back.
-f.
-
-
A really simple performance improvement is to enable page caching in ASP.Net.
An example OutputCache VaryByParams="none" Duration="60".
-f.
-
-
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.
-
-
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.
-
-
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.
-
-
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