943,701 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 570
  • C# RSS
Oct 19th, 2008
0

have a problem with inheritance

Expand Post »
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
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
polo_coins is offline Offline
63 posts
since Oct 2008
Oct 19th, 2008
0

Re: have a problem with inheritance

Have you tried:

C# Syntax (Toggle Plain Text)
  1. public class Child : Parent
Featured Poster
Reputation Points: 975
Solved Threads: 140
Posting Virtuoso
scru is offline Offline
1,624 posts
since Feb 2007
Oct 19th, 2008
0

Re: have a problem with inheritance

Click to Expand / Collapse  Quote originally posted by scru ...
Have you tried:

C# Syntax (Toggle Plain Text)
  1. 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
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
polo_coins is offline Offline
63 posts
since Oct 2008
Oct 19th, 2008
0

Re: have a problem with inheritance

OK but if you had

C# Syntax (Toggle Plain Text)
  1. class MyClass
  2. {
  3. private int myval =0;
  4. public MyClass (int value)
  5. {
  6. myval=value;
  7. }
  8.  
  9.  
  10. public int MyValue
  11. {
  12. return myval;
  13. }
  14. }

You would call this in your inherited with

C# Syntax (Toggle Plain Text)
  1. public MyNewClass : MyClass
  2. {
  3.  
  4. public int MyNewValue : base MyValue(1)
  5. {
  6.  
  7. }
  8.  
  9. }
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Oct 20th, 2008
0

Re: have a problem with inheritance

Thank LizR
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
polo_coins is offline Offline
63 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: merging image
Next Thread in C# Forum Timeline: Problem with keyboard control in C#





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC