Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Question in C# about Interfaces......

Question in C# about Interfaces......

Scheduled Pinned Locked Moved C#
helpquestioncsharptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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

    U 1 Reply Last reply
    0
    • L Lost User

      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

      U Offline
      U Offline
      Uri Lavi
      wrote on last edited by
      #2

      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

      L 1 Reply Last reply
      0
      • U Uri Lavi

        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

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Toda Gever. :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups