DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C# (http://www.daniweb.com/forums/forum61.html)
-   -   have a problem with inheritance (http://www.daniweb.com/forums/thread152136.html)

polo_coins Oct 19th, 2008 9:20 am
have a problem with inheritance
 
I built two different classes and I want that one class get inherit from another ,
but when I build Constructions Compiler throw me an Error.
I get to conclusion that i must use base function
so I build Constructor like this one :
public name_class:base()
my question what do I put between parentheses and if my syntax o.k and what is the right way to built such constructor

Thanks, sergey

scru Oct 19th, 2008 9:31 am
Re: have a problem with inheritance
 
Have you tried:

public class Child : Parent

polo_coins Oct 19th, 2008 9:42 am
Re: have a problem with inheritance
 
Quote:

Originally Posted by scru (Post 716083)
Have you tried:

public class Child : Parent

It's O.K. this thing I understand I mean syntax of building Constructors and call for Metgods of parents, I tried a couple things and here what I got :
public Name_of Chuld (type_of_variable name_of_it):base(name_of_this_variable_in_Parent)

and when I call for parent function :
base.Name_ofParentFunction();

are the other way of doing so, and how it will look like for calling Parent function that get's some variables from Main for example ?

Thanks Sergey

LizR Oct 19th, 2008 10:52 am
Re: have a problem with inheritance
 
OK but if you had

class MyClass
{
  private int myval =0;
  public MyClass (int value)
  {
    myval=value;
  }
 

  public int MyValue
  {
    return myval;
  }
}

You would call this in your inherited with

public MyNewClass : MyClass
{

  public int MyNewValue : base MyValue(1)
  {

  }

}

polo_coins Oct 20th, 2008 5:55 am
Re: have a problem with inheritance
 
Thank LizR


All times are GMT -4. The time now is 2:14 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC