I think the best thing here is to explain how you use the new keyword. new can be used in two modes. As an operator and as a modifier.
new "Operator"
The new operator is used to create objects and call constructors, for example:
Class1 MyClass = new Class1();
new modifier
Use the new modifier to explicitly hide an element inherited from the base class. To hide an inherited element, declare it in the derived class using the same name and change it with the new modifier.
Consider the following class:
public class MyBaseC { public int x; public void Invoke() {} }
Declaring a member named Invoke in a derived class will hide the Invoke method in the base class, that is:
public class MyDerivedC : MyBaseC { new public void Invoke() {} }
However, the x field will not be affected because it is not hidden by a similar name.
A name hiding through inheritance takes one of the following forms:
A constant, field, property, or type introduced into a class or struct hides all the base members of the class with the same name.
A method introduced in a class or struct hides properties, fields, and types with the same name in the base class. It also hides all methods of the base class with the same signature.
An index entered in a class or struct hides all indexes of the base class with the same signature.
Because you hide the name and declare a Maptile type, but initialize the GrassTile , the AND type of the Maptile parent type never initialized your Texture member, so you see null .
source share