-
-
When calling execute Scalar, we always begin by calling it with some code like
int i = cmd.ExecuteScalar();
What’s wrong with this picture?… what if, the first field of the first row is… NULL?
so…
int i;
object o = cmd.ExecuteScalar();
if(o != null)
i = (int)o;
-f.
-
-
Ever wonder of a more efficient way to write multiple lines strings?
Check this out…
The first way...
string myString1 = "This is the first line of my string.\n" +
"This is the second line of my string.\n" +
"This is the third line of the string.\n";
And a more efficient way...
string myString2 = @"This is the first line of my string.
This is the second line of my string.
This is the third line of the string.";
-f.
-
-
Embedding SQL statement is sometimes useful. A good practice is to centralize them in a class, using public constants...
public const string SQL_MYTABLE_INSERT = "INSERT MYTABLE (FIELD) VALUES (@FIELDVALUE)";
-f.
-
-
When adding a web service to your 2.0 .NET project, always begin by the same prefix, so, when the code will be generated, the namespace using will always be the same... like WebService.TheWSName and WebService.TheSecondWSName...
-f.
-
-
For production product, usage of public should be only used for publicly accessible methods, because all public methods can be used by other assembly/application than yours.
-f.
-
-
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.