Question in C# about Interfaces......
-
Hi, :rolleyes::rolleyes::rolleyes: I have 2 classes 1. Race 2. RunningRace. The first one is the base class and the other one Inherits from the first. I need to add method "ComperTo" for each of the classes - - so i add Inherits of the interface IComparable for each of those classes. My question are 1. Is there is other way to do it ? :confused: 2. I have 2 method with same name in this case and i cant add 'Virtual' keyword to any method so i have some problem that i don't know how to solve ... :confused: 3. If the base class Inherits interface - is the class that Inherits from him also must add the pure virtual method ? :confused: Thanks for any help. :-D
-
Hi, :rolleyes::rolleyes::rolleyes: I have 2 classes 1. Race 2. RunningRace. The first one is the base class and the other one Inherits from the first. I need to add method "ComperTo" for each of the classes - - so i add Inherits of the interface IComparable for each of those classes. My question are 1. Is there is other way to do it ? :confused: 2. I have 2 method with same name in this case and i cant add 'Virtual' keyword to any method so i have some problem that i don't know how to solve ... :confused: 3. If the base class Inherits interface - is the class that Inherits from him also must add the pure virtual method ? :confused: Thanks for any help. :-D
Hi, Add the "CompareTo" only to the Race class. Declare it as a virtual method (Just add the virtual keyword to its declaration). Provide an overrding to the "CompareTo" method in the RunningRace class.
public class Race : IComparable { ... public virtual int CompareTo(object obj){...} ... } public class RunningRace : Race { ... public override int CompareTo(object obj){...} ... }
Uri
-
Hi, Add the "CompareTo" only to the Race class. Declare it as a virtual method (Just add the virtual keyword to its declaration). Provide an overrding to the "CompareTo" method in the RunningRace class.
public class Race : IComparable { ... public virtual int CompareTo(object obj){...} ... } public class RunningRace : Race { ... public override int CompareTo(object obj){...} ... }
Uri