« February 2004 | Main | April 2004 »

Easily misunderstood options in RegEx

Posted by: David Carroll

OptionDescription
MultilineHas nothing to do with how many lines are in the input string. Rather, this simply modifies the behavior of ^ and $ so that they match BOL and EOL instead of the beginning and end of the entire input string.
IgnorePatternWhitespaceAllows pattern to have as much white space as desired, and also enables the use of in-pattern comments, using the (?# comment #) syntax.
SingleLineHas nothing to do with how many lines are in the input string. Rather, will cause the . (period) metacharacter to match any character, instead of any character except \n, which is the default.

How to implement Equals in C#

Posted by: David Carroll

public override bool Equals(object obj)
{
if (obj == null) return false;
if (this.GetType() != obj.GetType()) return false;
// safe because of the GetType check
Customer cust = (Customer) obj;
// use this pattern to compare reference members
if (!Object.Equals(Name, cust.Name)) return false;
// use this pattern to compare value members
if (!Age.Equals(cust.Age)) return false;
return true;
}