javac#arraysequivalent

What is the C# equivalent of Java's getComponentType()?


I am translating from Java to C# and have code similar to:

T[] @unchecked = (T[])Array.newInstance(array.getClass().getComponentType(), sampleSize);

I know getClass() equals to GetType() in C# and newInstance() equals to CreateInstance(); but idk what's the C# equivalent of getComponentType()?


Solution

  • Try this, it will work Array.CreateInstance(array.GetType().GetElementType(), sampleSize);