Thursday 13 March 2008

Custom operators in C# .NET

Below are two examples of how to create custom operators for your objects.

public static bool operator !=(BusinessEntityKey a, BusinessEntityKey b)
{
return !(a == b);
}


Another example...

public static bool operator ==(BusinessEntityKey a, BusinessEntityKey b)
{
if ((object)a == null && (object)b == null)
{
return true;
}
else if ((object)a == null (object)b == null)
{
return false;
}
else
{
return (a.businessEntitySysKey == b.businessEntitySysKey && a.timestamp == b.timestamp);
}
}

No comments: