Up casting - c#

前端 未结 6 1018
星月不相逢
星月不相逢 2021-01-17 15:57
public class a{
  public string x1 {get;set;}
  public string x2 {get;set;}
  public string x3 {get;set;}
}

public class b:a{
}

Obviously v

6条回答
  •  攒了一身酷
    2021-01-17 16:44

    As everyone's saying, it's not possible. Implicit casting is one solution, but I prefer to create a constructor on b that takes an instance of type a...

    That way you can either: hold a reference to that a internally and delegate to it calls b inherits from a, or just simply copy the values out of the type a.

提交回复
热议问题