I'm trying to figure out how to override variables spawned in a derived class that are declared in a base class.
For instance:
public class construct
{
public
bool DENSITY = false;}public class mob : construct
{
DENSITY = true;
}
Is this possible with some sort of modifier or something, or do I have to change DENSITY in a method/function/procedure/sub-routine (what name do C# programmers use?) in the derived class?

Jan MontanoRank #1,295 · 1.3K reputationPosted Jul 5, 2007, 6:43 PM EDT
AlanRank #669 · 3.6K reputationPosted Jul 6, 2007, 12:06 AM EDT
FWIW, you can hide a variable declared in a parent class by declaring a similarly named variable in a child class and preceding it with the 'new' keyword.
You can still access the parent class variable either by using a cast or (within the child class code) by using the 'base' keyword. For example:
using System;
class Program
{
static void Main()
{
mob m = new mob();
Console.WriteLine(m.DENSITY); // true
Console.WriteLine(((construct)m).DENSITY); // false
Console.WriteLine(m.BaseDensity); // false
m.BaseDensity = true;
Console.WriteLine(m.BaseDensity); // true
Console.ReadLine();
}
}
public class construct
{
public bool DENSITY = false;
}
public class mob : construct
{
public new bool DENSITY = true;
public bool BaseDensity
{
get {return base.DENSITY;}
set {base.DENSITY = value;}
}
}