It is possible to cast class1 to class2 ? result variable retrieves always null value.
class Program { static void Main(string[] args) { Class1 class1 = new Class1(); class1.Field1 = "1"; class1.Field2 = "2"; class1.Field3 = "3"; class1.Field4 = "4"; class1.Field5 = "5"; BaseClass base1 = (BaseClass)class1; Class2 class2 = base1 as Class2; string result = class2.Field1; } } public class BaseClass { public string Field1 { get; set; } public string Field2 { get; set; } public string Field3 { get; set; } } public class Class1 : BaseClass { public string Field4 { get; set; } public string Field5 { get; set; } } public class Class2 : BaseClass { public string Field6 { get; set; } public string Field7 { get; set; } }
BaseClassinstance and copies values from it. Casting using a custom operator would be confusing.