I'm learning how to program with C# WPF. I've created a class that derives from a base class. But there is only problem, it doesn't let me access variables from the base class even when my base class variables are public.
These are 2 seperate class files.
How do I use variables created from my base class, in my derived class?
7 replies to this topic
#1
Posted 06 May 2011 - 06:06 PM
|
|
|
#2
Posted 06 May 2011 - 11:44 PM
Post your code as there is no way for us to determine what you might be doing without it.
#3
Posted 07 May 2011 - 10:57 AM
file1: baseclass.cs
file2: derivedclass.cs
class baseclass
{
public int A = 10;
}
file2: derivedclass.cs
class derivedclass : baseclass
{
A = 20; //Compiler error here
}
#4
Posted 07 May 2011 - 01:27 PM
Of course there is an error, you can't put executable code in a class without a method. Has nothing to do with the base class.
#5
Posted 07 May 2011 - 02:06 PM
@Mien Tommy
try with this
try with this
...
class derivedclass: baseclass
{
int b;
b = a;
//if you are using console application then write Console.Write(b); and if you are using winforms then write MessageBox.Show("{0}",b);
}
#6
Posted 07 May 2011 - 02:08 PM
this is the simple example
#7
Posted 07 May 2011 - 03:34 PM
Tonchi said:
this is the simple example
#8
Posted 07 May 2011 - 04:03 PM
i know...this is only a clue...he should know how to write Main function if he starts C#
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









