Trying to put a generic MyObj<T, U> into an IList where U can be different between objects
Posted
by
Sergio Romero
on Stack Overflow
See other posts from Stack Overflow
or by Sergio Romero
Published on 2012-03-28T23:17:36Z
Indexed on
2012/03/28
23:31 UTC
Read the original article
Hit count: 285
I have the following class definition:
public interface IItem{}
public class FirstObject<T, U> : IItem
{
public U SomeProperty { get; private set; }
}
IList<IItem> myList = new List<IItem>();
I did it like this because U can be of different types. Now I want to iterate the list and get my items back, the problem is that I do not know how to cast them back to their original type so I can read the value of SomeProperty.
Thanks for your help.
© Stack Overflow or respective owner