-edit- Jason makes a good point that i could add both types to a list of A. But i cant use A due to reflections. Thus i want to know a way to convert the base data from one derive to another. I know in C++ in certain cases i could simply do *(A*)this = (A)that
. I am hoping there is something just as simple in C#.
I seriously do have the code below, just different names and types.
Since I need to add/create a list i cant use A (objects are expected to be B or C. Also A is abstract).
So i just made a List<B>
and i am looking for the easiest or 'best' way to do this code wise. I could add a ctor to C that takes in B but i would have to copy paste it to D, E, F if i choose to have them. So that isnt a great way. What is?
I was hoping Convert.ChangeType would work but that was too farfetched and didnt work. What are you suggestion guys?
abstract class A
{
public int a;
public SomeClass b;
public string c;
}
class B : A {}
class C : A {}
List<B> process(int data);
void func()
{
var b = process(...);
var cTemp = process(...);
//now to convert cTemp to C[] or any IEnumerable<C>
}