I have 2 classes:
public class Item {
//MyFields
}
public class ItemCapsule {
public Item MyItem { get; set; };
}
Somewhere in code, I write
ItemCapsule itemCapsule;
if (itemCapsule != null && itemCapsule.MyItem != null) {
//action
}
I might want to do this:
ItemCapsule itemCapsule;
if (itemCapsule != null) {
//action
}
So I created, in ItemCapsule, 2 methods to overload the operators
public static bool operator ==(ItemCapsule capsule, ???? what to write ????)
{
return ???? what to write ????;
}
public static bool operator !=(ItemCapsule capsule, ???? what to write ????)
{
return ???? what to write ????;
}
But, the problem is I do not know how to write the above two methods.
I want to do the following
ItemCapsule != null
which actually is suppose to do the following
ItemCapsule != null && ItemCapsule.MyItem != null
How do I do it?
Usually you do an overload for the
equalstoo.like so