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.
Unfortunately, activation email could not send to your email. Please try again.

GridBorder null values

Thread ID:

Created:

Updated:

Platform:

Replies:

1985 Dec 9,2002 08:13 AM Dec 9,2002 09:06 AM Windows Forms 1
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On December 9, 2002 08:13 AM

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

Administrator [Syncfusion]
Replied On December 9, 2002 09:06 AM

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 ) );

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;