473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

calling a variable from parent class to base class

Ranjith Reddy Bandi
i want to call a varible from parent class to base using inhertance in c#.net i please give immedate replay......Thank You
May 31 '07 #1
6 2015
mwalts
38
i want to call a varible from parent class to base using inhertance in c#.net i please give immedate replay......Thank You
I think there is a terminology issue here,

A parent class is a base class.

If you want to use a method from the class you inherit from, use the base keyword.

I think your going to have to re-word your question

-mwalts
May 31 '07 #2
cena
1
Hi Ranjith,
by using mybase property call the base class variable into child class
Jun 1 '07 #3
Munawar
12
Hi,

Yes in C# you can get any public member of parent class by using keyword "base"

Like here is scenario
Expand|Select|Wrap|Line Numbers
  1.  public class MyParent
  2.     {
  3.         public string parentString;
  4.  
  5.         public MyParent() {
  6.  
  7.             Console.WriteLine("Parent Constructor.");
  8.         }
  9.  
  10.         public MyParent(string myString)
  11.         {
  12.             parentString = myString;
  13.             Console.WriteLine(parentString);
  14.         }
  15.     public void print()
  16.         {
  17.  
  18.             Console.WriteLine( "Iam parent; " + parentString);
  19.  
  20.         }
  21. }
  22.  
  23. Class myChild : MyParent
  24. {
  25. //Calling parent constructor 
  26.          public MyChild() : base("From Derived")
  27.         {
  28.  
  29.             Console.WriteLine("Child Constructor");
  30.  
  31.         }
  32.  
  33. public new void print()
  34.         {
  35. //here you call parent property /member using base
  36. base.parentstring="munawar"
  37.             base.print();
  38.  
  39.             Console.WriteLine("I'm a Child Class.");
  40.  
  41.         }
  42.  
  43. }
  44.  
  45.  
  46.         public static void Main()
  47.         {
  48.  
  49.             MyChild child = new MyChild();
  50.  
  51.             child.print();
  52.  
  53.             ((MyChild)child).print();
  54.  
  55.         }
  56.  

Thanks
Munawar Hussain
Jun 1 '07 #4
Thank you...........
Jun 8 '07 #5
Hi cena
Can u give the syntax plzz....
Jun 8 '07 #6
Frinavale
9,735 Expert Mod 8TB
Hi cena
Can u give the syntax plzz....
Hi Ranjith,
Welcome to TDSN.

Have you tried Munawar's example?
It seems pretty complete to me.

-Frinny
Jun 8 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Axel Straschil | last post by:
Hello! Im working with new (object) classes and normaly call init of ther motherclass with callin super(...), workes fine. No, I've got a case with multiple inherance and want to ask if this...
5
by: Bob Hairgrove | last post by:
Consider the following: #include <string> class A { public: A( const std::string & full_name , const std::string & display_name) : m_full_name(full_name)
2
by: William Payne | last post by:
Hello, consider these following two classes. A base class, class MDIChildWindow, and a class inherting from that base class, class Document. In the static base member function callback() I obtain a...
3
by: scott | last post by:
hi all, hope some one can help me. Ill try and explain what im trying to do as best i can. i have a parent class that has a vertual function, lets call it virtual int A(). That vertual function...
1
by: NOSPAM | last post by:
I have a question on calling parent class... What I want to do is: when calling the derived class, it automatically executes the parent's method, is it possible? // main code: Derived d = new...
1
by: smeagol | last post by:
Look this code, well, you know how it works, in "public server (client cl) { cl.Write(); }" "client" is a know class name, but if somebody write a custom start class (like client) and it call to...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
12
by: st_ev_fe | last post by:
I've noticed that when constructing a subclass, the base class get's it's contructors called. Is there some way to avoid this? The base class has one variable, which gets initialised to 0. ...
12
by: Peter Cranz | last post by:
hello, I've got the following problem: I have a construct similar like this: namespace A { class X {
1
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
The code below is pretty simple. Calling Talker() in the parent returns "Parent", and calling Talker() in the child returns "Child". I'm wondering how I can modify the code so that a call to the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.