Aslam-o-Alaikum
Can we fixed the generic collections as array..............?
Loading
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
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Feb 21, 2011, 10:49 PM EST
Can you ask the question clearly. So that we can understand better and will clear your doubt.
Amit ChoudharyRank #145 · 15.8K reputationPosted Feb 21, 2011, 11:12 PM EST
you can create your own custom array using the Array class see the below example:
Creating an Array
Array class provides the CreateInstance method to construct an array. The CreateInstance method takes first parameter as the type of items and second and third parameters are the dimension and their range. Once an array is created, we use SetValue method to add items to an array.
The following code snippet creates an array and adds three items to the array. As you can see the type of the array items is string and range is 3. You will get an error message if you try to add 4th item to the array.
Array stringArray = Array.CreateInstance(typeof(String), 3);
stringArray.SetValue("Mahesh Chand", 0);
stringArray.SetValue("Raj Kumar", 1);
stringArray.SetValue("Neel Beniwal", 2);
Note: Calling SetValue on an existing item of an array overrides the previous item value with the new value.
The code snippet in Listing 2 creates a multi-dimensional array.
Array intArray3D = Array.CreateInstance(typeof(Int32), 2, 3, 4);
for (int i = intArray3D.GetLowerBound(0); i <= intArray3D.GetUpperBound(0); i++)
for (int j = intArray3D.GetLowerBound(1); j <= intArray3D.GetUpperBound(1); j++)
for (int k = intArray3D.GetLowerBound(2); k <= intArray3D.GetUpperBound(2); k++)
{
intArray3D.SetValue((i * 100) + (j * 10) + k, i, j, k);
}
foreach (int ival in intArray3D)
{
Console.WriteLine(ival);
}Source Article: http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingWithArrays11232005064036AM/WorkingWithArrays.aspx
Thanks
Sam HobbsRank #107 · 20.5K reputationPosted Feb 22, 2011, 5:13 PM EST