I want this to tell me the Name of both ItemA and ItemB. It should tell me "Subitem Subitem", but instead it tells me "Item Subitem". This is because the "Name" variable defined in the Subitem class is technically a different variable than the "Name" variable defined in the base Item class. I want to change the original variable to a new value. I don t understand why this isn t the easiest thing ever, considering virtual and override work perfectly with methods. I ve been completely unable to find out how to actually override a variable.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Example
{
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine(ItemA.Name);
System.Console.WriteLine(ItemB.Name);
System.Console.ReadKey();
}
static Item ItemA = new Subitem();
static Subitem ItemB = new Subitem();
}
public class Item
{
public string Name = "Item";
}
public class Subitem : Item
{
new public string Name = "Subitem";
}
}