Array Class
Array class is a abstract class so we can not create object for abstract classes so how we create array can you explain the internal process
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Piotr Justyna70 reputationPosted Nov 26, 2009, 5:50 AM EST
Array sampleArray = Array.CreateInstance(Type.GetType("String"), 2);
This will create an instance of an one-dimensional array, which can contain 2 elements of type 'String'. This is 100% correct but it's a lot easier to use this array:
String[] sampleArray1 = new String[2];
String[] sampleArray2 = new String[] { "String 1", "String 2" };
In the first case you create an array with uninitialized elements (both are null) and in the second case sampleArray2 has 2 initialized elements ("String 1" and "String 2"). I hope this will help you.
Cheers!
theLizardRank #1,079 · 1.8K reputationPosted Nov 26, 2009, 10:37 AM EST
int[] j = new int[0]; //zero elements
--> Array.Resize(ref j, j.Length +1); //increase size of array by one (1)
This is most useful in while or for loops.
eg.
int i = 0;
while(i != recordCount){
Array.Resize(ref j, j.Length +1);
j[i]= i;
i++;
}
srinivas137 reputationPosted Nov 30, 2009, 5:58 PM EST
Piotr Justyna70 reputationPosted Dec 1, 2009, 12:29 AM EST
There's no possibility of creating abstract class object. The only thing you can do is to implement that abstract class and then instanciate the implementing class (of course making sure, that the implementing class is not abstract too :) )
Please mark my answer as helpful if you like it.
Cheers!