?
Solved

basic c# question

Posted on 2006-11-06
8
Medium Priority
?
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 22

Accepted Solution

by:
_TAD_ earned 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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:K V
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:K V
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:K V
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

771 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