So I'm trying to understand up-casting and down-casting in c#.
My question is, is this diagram correct or am I still missing something? If its incorrect, where can I find a diagram that represents this concept correctly?
Any help is greatly appreciated.
Edit: Firstly I apologize for the confusion, I realize the diagram is not very clear and that I made a mistake in the down-casting one (where circle2 only has access to string Colour, it should have access to all the properties). I'll try and explain better what I was trying to represent.
So, here is the code that would go with it:
public class Shape
{
public int Width {get;set;}
public int Height {get;set;}
public int X {get;set;}
public int Y {get;set;}
public void Draw()
{
//do something
}
}
public class Circle : Shape
{
public string Colour {get;set;}
}
public class Program
{
public static void Main(string[] args)
{
//Up-casting
Circle circle = new Circle(); //object is created
Shape shape = circle; // shape point to circle object
//Down-casting
Circle circle2 = (Circle)shape;
}
}