I know casting is not inherently bad practice, but is it bad in this situation?
I have the following class hierarchy, and the cast at the end.
public class A<T> { public A(string name, T value) { Name = name; Value = value; } public string Name { get; } public T Value { get; } } public class B : A<double> { public B(string name, double value, string expression) : base(name, value) { Expression = expression; } public string Expression { get; } } public class C { public C(A<double> a) { _a = a; } public string Name { get { return _a.Name; } } public double Value { get { return _a.Value; } } protected A<double> _a; } public class D : C { public D(B b) : base(b) { } public string Expression { get { return ((B)_a).Expression; } } } The line in question: public string Expression { get { return ((B)_a).Expression; } }