String.Format is just so cool. It makes your code less spaghetti like and makes it easier to replace string values or add new values. It also allows you to see from a quick glance what your code does. It also makes it MUCH easier to update your string and add more parameters to it. It works similarly to the printf function in C++ that takes a string, and then is followed by parameters that specify what to plug into the string.
Tryparse is a C# function that you can use to convert from a string to another data type such as integer. It allows you to avoid throwing exceptions and catching them. This can be a more efficient way to write your code and avoid clunky exceptions. It returns true if the conversion succeeds, so you can also use it to test if a string is numeric or not.
Proper exception handling is part of writing good code. Here’s a quick tip – if you don’t want to handle an exception, fine, just leave it., don’t put any try/catch and just let the exception propogate up to it’s caller.
If you are not sure why you are using try/catch, maybe you shouldn’t be [...]
Let’s define a nullable. You can declare a variable as nullable, for example
int ? x;
You are saying that the int might have a value, or it might have a null value. This is convenient
Now in your code you might want to check and see if its actually null and if it [...]
This article summarizes some nice ways to create SqlParameter arrays. When we use SqlHelper, or even without SqlHelper when we use SqlCommands directly, and we want to pass an array of SqlParameters to the function. The method I will discuss does not require you to hard-code the number of elements, nor does it require you [...]
-
Articles
- January 2011
- April 2010
- March 2010
- February 2010
- January 2010
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- February 2009
- December 2008
- November 2008
- October 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
-
Meta
