Use Type.TryParse rather than Convert.ToDestinationType(). For example use int.TryParse() rather than Convert.ToInt32() which might throw an exception.
Override Equals() method wherever applicable in your classes.
Consider passing base types as parameters - Using base types as parameters to methods improves re-use of these methods if you only use methods & properties from the parameter's base class. E.g. use Stream instead of FileStream as a parameter when only calling Stream.Read(), this makes the method work on all kind of streams instead of just File streams.
To test for empty strings, check if String.Length is equal to zero. Constructs such as "".Equals(someString) and String.Empty.Equals(someString) are less efficient than testing the string length. Replace these with checks for someString.Length == 0.
Move the reusable javascript functions to an external .js file instead of having them on the page.
For controls that are declarativley specified on the page, tie the event handlers to the controls events on the aspx page rather than initializing them in the codebehind. If the controls are built dynamically then we donot have a choice.
Make sure to check for nulls when using any type retrieved from a session, querystring or a database
to avoid NullReferenceExceptions.
Use foreach loop instead of using for loop which may lead to out of boundary run time exceptions.
No comments:
Post a Comment