I've made myself a rss reader that keeps me up to date and informs me on new shows, or atleast thats the thought behind.
I've made a struct "SeasonEpisode" that hold two ints (season+episode) and a override ToString function.
I store the latest watched locally and i then read whats the newest is from the rss. But how could I compare SeasonEpisodes? right now I take each of the ints and compare them
if( se1.Season >= se2.Season )
if( se1.Episode > se2.Episode || se1.Season > se2.Season )
// new episode!
What i really want is
if( se1 > se2 )
// new episode
Could i get any help please?
Polymorphism: Polymorphism (or operator overloading) is a manner in which OO systems allow the same operator name or symbol to be used for multiple operations. That is, it allows the operator symbol or name to be bound to more than one implementation of the operator. A simple example of this is the “+” sign.
Operator overloading is a compile-time polymorphism in which the operator is overloaded to provide the special meaning to the user-defined data type. Operator overloading is used to overload or redefines most of the operators available in C++. It is used to perform the operation on the user-defined data type.
Function overloading means using a single name and giving more functionality to it. Operator overloading means adding extra functionality for a certain operator. When an operator is overloaded, the operator has different meanings, which depend on the type of its operands.
1) Only built-in operators can be overloaded. New operators can not be created. 2) Arity of the operators cannot be changed. 3) Precedence and associativity of the operators cannot be changed.
There are two ways:
IComparable<T>
and use CompareTo
I suggest, you use both ways:
public class SeasonEpisode : IComparable<SeasonEpisode>
{
public int CompareTo(SeasonEpisode other)
{
if(other == null)
return 1;
if(Season == other.Season)
{
if(Episode == other.Episode)
return 0;
else if(Episode < other.Episode)
return -1;
else
return 1;
}
else if(Season < other.Season)
return -1;
else
return 1;
}
public static bool operator <(SeasonEpisode e1, SeasonEpisode e2)
{
return e1.CompareTo(e2) < 0;
}
public static bool operator >(SeasonEpisode e1, SeasonEpisode e2)
{
return e1.CompareTo(e2) > 0;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With