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

Recommended Answers

All 4 Replies

Have you tried:

public class Child : Parent

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

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)
  {

  }

}

Thank LizR

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.