Solved

basic c# question

Posted on 2006-11-06
8
204 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now