http://stackoverflow.com/a/30027307/3094533 Zohar peled

CSharp · Console

/Program.cs

using System;
					
public class Program
{
    public class Fruit { public string Name { get; set; } }
    public class Apple : Fruit { }

    public static void ReadFruitData(string Name, ref Fruit newFruit)
    {
        // All I did was removing the newFruit = new Fruit(); line from here.
		newFruit.Name = Name;
    }

    public static void ReadAppleData(string Name, ref Apple newApple)
    {
        Fruit f = (Fruit)newApple;

        ReadFruitData(Name, ref f);
    }
    
    public static void Main(string[] args)
    {
        Apple a = new Apple();
        ReadAppleData("ab", ref a);
		
		Console.WriteLine("The name of the apple is '{0}'.", a.Name);
	}
}

;