<meta http-equiv="X-UA-Compatible" content="IE=7" />
Wednesday, August 19, 2009
Only IE7 in IE8
Monday, August 17, 2009
Escaping xml data
Sunday, August 2, 2009
String.Empty vs empty quotes vs String.Length
The usage of String.Empty is more efficient that the usage of empty quotes.
When using empty quotes an object is created and this produces more assembly code on the execution stack and for string.Empty is NO object created.
The usage of String.Length == 0 is the best. Now there is a numeric compare applied instead of a string compararision, and numeric compare is quicker.
Only what if the string has the value null? So use string.IsNullOrEmpty method
More info: C# Shiznit, Vikram's Blog
Throw; versus Throw e;
In Coding Standards is the differents between throw and throw e explained.
What is the difference?
The difference is that 'throw;' the original stack trace persists and 'throw ex' truncates the stack trace after the method where the 'throw ex;' is called.
When using 'throw;'?
When in the try{...} a method is called then you must use 'throw;' to take care that you have the original stack trace.
Example:
// Bad!
catch(Exception ex)
{
Log(ex);
throw ex;
}
// Good!
catch(Exception)
{
Log(ex);
throw;
}
Another alternative is to create a new Exception and pass the current exception as inner exception. The stack trace is shown correctly (complete)
Example:
// Bad!
catch(Exception ex)
{
Log(ex);
throw ex;
}
// Good!
catch(Exception)
{
Log(ex);
Throw new NotImplementedException(“some extra information”, ex);
}
See for more information Fabrice's weblog, Signs on the Sand, Joteke's Blog
String.Compare or String.ToLower
// Bad!
Example: (ToLower() creates a temp string)
int id = -1;
string name = "lance hunt";
for(int i=0; i < customerList.Count; i++)
{
if(customerList[i].Name.ToLower() == name)
{
id = customerList[i].ID;
}
}
// Good! (but not for all cultures)
int id = -1;
string name = "lance hunt";
for(int i=0; i < customerList.Count; i++)
{
// The “ignoreCase = true” argument performs a
// case-insensitive compare without new allocation.
if(String.Compare(customerList[i].Name, name, true)== 0)
{
id = customerList[i].ID;
}
}
// Good! (now also for all cultures)
int id = -1;
string name = "lance hunt";
for (int i = 0; i < customerList.Count; i++)
{
// The StringComparison.OrdinalIgnoreCase argument performs a
// case-insensitive compare without new allocation and for several cultures.
if (String.Compare(customerList[i].Name, name, StringComparison.OrdinalIgnoreCase) == 0)
{
id = customerList[i].ID;
}
}
Een leuke referentie is de zogenaamde Turkey Test.
Monday, July 27, 2009
Countries depending CurrentCultureInfo
Wednesday, July 1, 2009
Refactoring methods
I try myself to read this list and also use this list during programming. And when I optimize some code fragment I want to realize that I am using one of these refactoring methods.