Click here to Skip to main content
15,923,909 members
Home / Discussions / C#
   

C#

 
QuestionWindows file metadata Pin
asgardh23-May-08 15:13
asgardh23-May-08 15:13 
QuestionAbstract Classes and Interfaces Pin
Jacob Dixon23-May-08 13:31
Jacob Dixon23-May-08 13:31 
AnswerRe: Abstract Classes and Interfaces Pin
Anthony Mushrow23-May-08 14:00
professionalAnthony Mushrow23-May-08 14:00 
GeneralRe: Abstract Classes and Interfaces Pin
Jacob Dixon23-May-08 14:22
Jacob Dixon23-May-08 14:22 
GeneralRe: Abstract Classes and Interfaces Pin
Anthony Mushrow23-May-08 14:33
professionalAnthony Mushrow23-May-08 14:33 
GeneralRe: Abstract Classes and Interfaces Pin
Jacob Dixon23-May-08 14:39
Jacob Dixon23-May-08 14:39 
GeneralRe: Abstract Classes and Interfaces [modified] Pin
Roger Alsing23-May-08 23:10
Roger Alsing23-May-08 23:10 
GeneralRe: Abstract Classes and Interfaces Pin
Jacob Dixon24-May-08 5:34
Jacob Dixon24-May-08 5:34 
So something like this?

namespace IT274_U2
{
    public interface IAnimal
    {
        string WhatAmI { get; }
        string WhatIsMyName { get; }
    }

    public abstract class Animal : IAnimal
    {
        private string _WhatAmI;
        private string _WhatIsMyName;

        public Animal(string WhatAmI, string WhatIsMyName)
        {
            _WhatAmI = WhatAmI;
            _WhatIsMyName = WhatIsMyName;
        }
        public string WhatAmI
        {
            get
            {
                return _WhatAmI;
            }
            set
            {
                _WhatAmI = value;
            }
        }
        public string WhatIsMyName
        {
            get
            {
                return _WhatIsMyName;
            }
            set
            {
                _WhatIsMyName = value;
            }
        }
    }
    public class Cat : Animal    
    {       
        public Cat(string WhatAmI, string WhatIsMyName) : base ("Cat",WhatIsMyName)    
        {
        }
    }
    public class Dog : Animal
    { 
        public Dog(string WhatAmI, string WhatIsMyName) : base("Dog", WhatIsMyName)
        {
        }
    }

    public class TesterClass
    {
        static void DescribeAnimal(IAnimal animal)
        {
            Console.WriteLine("My name is {0}, I am a {1}", animal.WhatIsMyName, animal.WhatAmI);
        }

        static void Main(string[] args)
        {
            Dog mydog = new Dog("Dog", "Spot");
            Cat mycat = new Cat("Cat", "Felix");
            DescribeAnimal(mydog);
            DescribeAnimal(mycat);
            Console.ReadKey();
        }
    }
}


Ok It works, but I do not really understand where base() comes from. Now how does this work even though the methods Dog() and Cat() have nothing in them?!?
GeneralRe: Abstract Classes and Interfaces Pin
Jacob Dixon24-May-08 6:04
Jacob Dixon24-May-08 6:04 
GeneralRe: Abstract Classes and Interfaces Pin
Jacob Dixon24-May-08 6:10
Jacob Dixon24-May-08 6:10 
AnswerRe: Abstract Classes and Interfaces Pin
PIEBALDconsult23-May-08 18:43
mvePIEBALDconsult23-May-08 18:43 
GeneralRe: Abstract Classes and Interfaces Pin
Jacob Dixon24-May-08 5:23
Jacob Dixon24-May-08 5:23 
QuestionLog reader, generating events from recorded timestamp Pin
GuimaSun23-May-08 13:18
GuimaSun23-May-08 13:18 
QuestionHow to remove Duplicated rows from DataTable ? Pin
hdv21223-May-08 12:03
hdv21223-May-08 12:03 
AnswerRe: How to remove Duplicated rows from DataTable ? Pin
Christian Graus23-May-08 12:12
protectorChristian Graus23-May-08 12:12 
GeneralRe: How to remove Duplicated rows from DataTable ? Pin
hdv21223-May-08 12:14
hdv21223-May-08 12:14 
GeneralRe: How to remove Duplicated rows from DataTable ? Pin
Christian Graus23-May-08 12:28
protectorChristian Graus23-May-08 12:28 
GeneralRe: How to remove Duplicated rows from DataTable ? Pin
hdv21223-May-08 12:31
hdv21223-May-08 12:31 
QuestionConnect to biometric device Pin
Krazy Programmer23-May-08 7:38
Krazy Programmer23-May-08 7:38 
AnswerRe: Connect to biometric device Pin
led mike23-May-08 8:14
led mike23-May-08 8:14 
AnswerRe: Connect to biometric device Pin
carbon_golem23-May-08 9:03
carbon_golem23-May-08 9:03 
AnswerRe: Connect to biometric device Pin
Thomas Stockwell23-May-08 9:59
professionalThomas Stockwell23-May-08 9:59 
GeneralRe: Connect to biometric device Pin
Krazy Programmer23-May-08 20:42
Krazy Programmer23-May-08 20:42 
Questionget the time diffrence Pin
Boshkash23-May-08 7:36
Boshkash23-May-08 7:36 
AnswerRe: get the time diffrence Pin
Giorgi Dalakishvili23-May-08 7:41
mentorGiorgi Dalakishvili23-May-08 7:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.