Solved

basic c# question

Posted on 2006-11-06
8
203 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

12 Experts available now in Live!

Get 1:1 Help Now