Solved

basic c# question

Posted on 2006-11-06
8
206 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

860 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