I want to cast a generic class to its base type, having the class and the type inheritance.
I have these classes:
public class Segment<K> : SomeStructure where K : SomeStructure{...}
public class XXXXXXData : Segment<Key> {...}
public class Key : SomeStructure {...}
I have an instance of XXXXXXData
called data
but if I make a cast like
data as Segment<SomeStructure>
It returns null
.
Where I have these code, the variable can be a XXXXData
or any kind of Segment<>
. What can I do to cast to Segment<AmtsCobolStructure>
so I could use the methods of these base class?