I have a class where I need the constructor to initialize variable array. I researched on the internet and also stack overflow but now I am stuck on how to call the method. For example how could I call method1 in my example?
public class SomeClass<T>{
public T[] array;
//Constructor
public SomeClass()
{
Method1(T, 5); //? error
Method1(5); //? error
Method1(new T().GetType(), 5); //? error
// HOW CAN I CALL THAT METHOD?
array = (T[])(new Object[5]); // this gives an error too
}
private void Method1(Class<T> type, int size)
{
array = (T[])Array.newInstance(type, size);
}
}