I need to make container class for different structs(which inherit after same interface) but the thing is container needs to have GetStructAt(int index) method which returns non-nullable type.
Example:
public interface IExampleInterface
{}
public struct A : IExampleInterface
{
//some code
}
public struct B : IExampleInterface
{
//some code
}
public class Containter
{
List<IExampleInterface> list = new List<IExampleInterface>();
public /*SOMETHING*/ GetStructAt(int index)
{
return list[index];
}
public void AddStruct<T>(T toAdd) where T : struct, IExampleInterface
{
list.Add(toAdd);
}
}
What should I put in place of "/SOMETHING/ to get non-nullable type or is there any other way, maybe even without interfaces(which are not a must)?
My usecase is holding some components(which must be struct) of specific objects in this container to then add them to objects when needed. Adding to objects needs non-nullable type(I can't change it)