Solved

basic c# question

Posted on 2006-11-06
8
205 Views
Last Modified: 2010-04-16
Hi

I don't program in c# and i have to do something in this language in a bit of a rush.

How would i create an abstract superclass that had several properties and then 2 classes that inherit from this superclass (they must inherit all of the get/set methods). could you just show me a basic example. I am sure there are tonnes of examples of the internet but i just need a basic bare bones one to get me started so i thought i would ask here.

thanks a lot
andrea
0
Comment
Question by:andieje
8 Comments
 
LVL 22

Accepted Solution

by:
_TAD_ earned 500 total points
ID: 17885000


// public abstract superclass that inherits from the Object class
public abstract class SuperClass: Object
{
   public abstract string Property1;
   public abstract int Property2;
   public abstract object Property3;
}


public class SubClass1: SuperClass
{
    public string Property1
    {
         get{//do stuff}
         set{//do stuff}
    }
    public int Property2
    {
         get{//do stuff}
         set{//do stuff}
    }
    public object Property3
    {
         get{//do stuff}
         set{//do stuff}
    }

}


0
 
LVL 22

Expert Comment

by:_TAD_
ID: 17885001


// public abstract superclass that inherits from the Object class
public abstract class SuperClass: Object
{
   public abstract string Property1;
   public abstract int Property2;
   public abstract object Property3;
}


public class SubClass1: SuperClass
{
    public string Property1
    {
         get{//do stuff}
         set{//do stuff}
    }
    public int Property2
    {
         get{//do stuff}
         set{//do stuff}
    }
    public object Property3
    {
         get{//do stuff}
         set{//do stuff}
    }

}


0
 
LVL 22

Expert Comment

by:_TAD_
ID: 17885002


// public abstract superclass that inherits from the Object class
public abstract class SuperClass: Object
{
   public abstract string Property1;
   public abstract int Property2;
   public abstract object Property3;
}


public class SubClass1: SuperClass
{
    public string Property1
    {
         get{//do stuff}
         set{//do stuff}
    }
    public int Property2
    {
         get{//do stuff}
         set{//do stuff}
    }
    public object Property3
    {
         get{//do stuff}
         set{//do stuff}
    }

}


0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 15

Expert Comment

by:ozymandias
ID: 17885019

public abstract SuperClass{

    protected int _anInteger;
    protected string _aString;
    protected bool _aBoolean;

    public int AnInteger{
        get{
            return this._anInteger;
        }
        set{
            this._anInteger = value;
        }
    }

    public int AString{
        get{
            return this._aString;
        }
        set{
            this._aString = value;
        }
    }

    public int ABoolean{
        get{
            return this._aBoolean;
        }
        set{
            this._aBoolean = value;
        }
    }

}

public SubClass1 : SuperClass{


}

public SubClass2 : SuperClass{


}
0
 
LVL 2

Expert Comment

by:Sinclair
ID: 17886031
shouldn't you declare the properties as virtual ?
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 17887088
ozymandias seems right but i suppose a MUSTINHERIT keyword should be added !!
as your sentense "(they must inherit all of the get/set methods)"... suggests
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 17887100
i'm sorry to say my above comment is bit comfusing as mustinherit in vb = abstract in c# ...so ozy is right
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 17895549
hay TOD dont you think your answer doesnt satisfy this condition?
"(they must inherit all of the get/set methods)"

superclass should be having get/set and they should be inherited by subclass?!!
please justify your answer !
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question