P
Paul Lyons
Not sure how I've not come across this before...
I've overloaded operator == for one of my classes using
the following code.
public static bool operator ==(Stock x, Stock y)
{
return x.Equals(y);
}
public override bool Equals(object obj)
{
Stock queryObject = null;
if (obj is Stock)
queryObject = (Stock) obj;
else
return false;
return ((queryObject.StockCode == this.StockCode));
}
In another class I have the following code:
private Stock _stock = null;
private Stock getStock()
{
if (_stock == null) // Error here...
{
_stock = new Stock()
// populate details
}
}
My error occurs, because I initialise my local copy to
null, so it has no methods...
How do I check whether or not my object is null??
Thanks in advance
Paul
I've overloaded operator == for one of my classes using
the following code.
public static bool operator ==(Stock x, Stock y)
{
return x.Equals(y);
}
public override bool Equals(object obj)
{
Stock queryObject = null;
if (obj is Stock)
queryObject = (Stock) obj;
else
return false;
return ((queryObject.StockCode == this.StockCode));
}
In another class I have the following code:
private Stock _stock = null;
private Stock getStock()
{
if (_stock == null) // Error here...
{
_stock = new Stock()
// populate details
}
}
My error occurs, because I initialise my local copy to
null, so it has no methods...
How do I check whether or not my object is null??
Thanks in advance
Paul