We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

GridBorder null values

Hi, I am using custom borders and came across a strange behaviour with null values. Here is my code snippet: GridBorder border = null; Console.WriteLine("Border == null? " + (border == null) ); Console.WriteLine("Border != null? " + (border != null) ); output: border == null? False border != null? False Is this done by design or a bug? How do I check for null GridBorder values? thanks, - Reddy

1 Reply

AD Administrator Syncfusion Team December 9, 2002 02:06 PM UTC

This is by design. We recommend you use GridBorder.Empty instead of null. Generally, trying to use null directly, eventually runs into problems that can be avoided by using GridBorder.Empty. Here is the code that defines the == and != operators in the GridBorder class. In particular, if either argument is null, the == returns false.
/// 
///		The basic == operator.
/// 
/// The left-hand side of the operator
/// The right-hand side of the operator
/// 
///		bool
///	
public static bool operator==( GridBorder lhs, GridBorder rhs ) 
{                            
          if ((object) lhs == null || (object) rhs == null)
		return false;
	return lhs.Equals(rhs);
}

/// 
///		The basic != operator
/// 
/// The left-hand side of the operator
/// The right-hand side of the operator
/// 
///		bool
///	
public static bool operator!=( GridBorder lhs, GridBorder rhs ) 
{          
          if ((object) lhs == null || (object) rhs == null)
		return false;
	return !lhs.Equals(rhs);
}
But if you use the static GridBorder.Empty member to flag 'null's, this code works.
	GridBorder border = GridBorder.Empty;
	Console.WriteLine("Border == null? " + (border == GridBorder.Empty ));
	Console.WriteLine("Border != null? " + (border != GridBorder.Empty ) );

Loader.
Up arrow icon