Skip to main content

Posts

Showing posts with the label FxCop

Constructors for user defined Exceptions in C#

The following are the rules that are to be adhered to when creating any custom user  defined exception. 1. Follow the Naming convention so that the self-explanatory name of the exception ends with Exception like: ArgumentNullException. 2. The following constructors should be defined public NewException() public NewException(string message) public NewException(string message, Exception exception) protected or private NewException(SerializationInfo serializationInfo, StreamingContext streamingContext) These ensure that the created Exception satisfies the default rules of User Defined Exceptions. [Also Satisfies FxCop Validation] -- Saravanan

Comparing Strings in C#.Net

In order to compare strings for their equivalence, we have to follow this Rule from Microsoft " When you specify either  StringComparison.Ordinal  or  StringComparison.OrdinalIgnoreCase , the string comparison will be nonlinguistic. That is, the features that are specific to the natural language are ignored when comparison decisions are made. This means the decisions are based on simple byte comparisons and ignore casing or equivalence tables that are parameterized by culture." -- Saravanan