Not 100% sure if I fully understood the question but i'll give the reply my
best shot.
"to reference up the class chain, how do i reference the super class
(parent)?"
In your example:
mybase->myClass->Another
An instance of "another" IS also a class of MyClass and MyBase. There is no
need to reference these classes because the class you are in IS the same
class.
Let us extend the example a little.
public class MyBase
{
private int m_Number = 1;
protected int Number
{
get{return m_Number;}
}
}
If the base class was defined like this you could easily do the following.
public class MyClass:MyBase
{
public MyClass()
{
}
public void WriteNumber()
{
Console.WriteLine(Number);
}
}
Because MyClass has access to all of the public and protected members of
MyBase.
The base keyword is only used in the following circumstances:
a) In constructor logic
b) In overrides or "news"
e.g.
public class MyBase
{
private int m_Number;
protected int Number
{
get{return m_Number;}
}
public MyBase()
{
}
public MyBase(int number)
{
m_Number = number;
}
}
public class MyClass:MyBase
{
// we pass the argument down to the base constructor
// that accepts an int
public MyClass(int number):base(number)
{
}
}
Override usage:
public class MyBase
{
public MyBase()
{
}
protected virtual void WriteText()
{
Console.WriteLine("I'm the base class");
}
}
public class MyClass:MyBase
{
public MyClass()
{
}
protected override void WriteText()
{
Console.WriteLine("I'm NOT the base class");
Console.WriteLine("This is the output of the base class:");
// here we access the method we have overridden
base.WriteText();
}
}
I don't fully understand your second question.
For a class to "own" another class, do you mean that they have an instance
of the other class as a member or they are the ONLY class that can create an
instance of the other class?
If you only need an instance then declaring it as a member (as you did in
your example) is correct.
If you want ClassX to be the only class that can use ClassY then do this.
public class ClassX
{
private ClassY cy = new ClassY();
public ClassX()
{
}
private ClassY
{
public ClassY()
{
}
}
}
Because ClassY is nested within ClassX and is private it cannot be created
by any other class but ClassX
HTH
Simon
"MarkJ" <dv*****@sbcglobal.netwrote in message
news:rJ******************@newssvr14.news.prodigy.n et...
him im kinda new to c-sharp...
to reference up the class chain, how do i reference
the super class (parent)
example
class mybase
{
protected int abc=0
}
classs myclass:mybase
{
}
class another:myclass
{
public another()
{
// how would i reference up the inherit
int efg
efg=base:base:abc
}
}
// 2nd Question
ownership
if i instantiate a class from a top level of the app
how would i assign a owner to the class
example
class App
{
myclass oClass = new Myclass
// how can i assign App class as owner of myclass
}
thanks
MarkJ