Method(1):
Following code can also be used to convert Supported array into 2 Dimensional Array and print the 2D Array.
public static readonly string[] Supported = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
static void Main(string[] args)
{
int noOfCols = 6;//your own choice to split w.r.t columns
int noOfRows=Supported.Length/noOfCols;
string[,] array2D=new string[noOfRows,noOfCols];
int n = 0, m = 0;
for(int i=0;i<Supported.Length;i++)
{
array2D[n, m] = Supported[i];
m++;
if((m=m%noOfCols)==0)
{
n++;
}
}
}
Method(2):
We can also use the multi-threading process to assign values parallel in 2D array from start to Mid-Point and Last to next of Mid-point of supported Array.But keep in mind, this mechanism will be used where we have large amount of data in single array or in list of array,so you can make its small chunks and can use them to fill by threads parallel as such taking advantage of Multi-Threading.But I'm using only two threads to fill that one by this new method.
Thread thread1 = new Thread(delegate(){
FillFromZeroToMidIndex(array2D, Supported.Length / 2,noOfCols);
});
Thread thread2 = new Thread(delegate()
{
FillFromLastToMidUpIndex(array2D, (Supported.Length / 2) + 1, Supported.Length - 1, noOfCols,noOfRows);
});
thread1.Start();
thread2.Start();
while (thread1.IsAlive || thread2.IsAlive) { }
these are the two methods for thread1 and thread2
static void FillFromZeroToMidIndex(string[,] array2D,int midIndex,int noOfCols)
{
int n = 0, m = 0;
for (int i = 0; i<=midIndex; i++)
{
array2D[n, m] = Supported[i];
m++;
if ((m = m % noOfCols) == 0)
{
n++;
}
}
}
static void FillFromLastToMidUpIndex(string[,] array2D, int midUpIndex, int lastIndex, int noOfCols, int noOfRows)
{
int n = noOfRows-1, m = noOfCols-1;
for (int i = lastIndex; i >= midUpIndex; i--)
{
array2D[n, m] = Supported[i];
m--;
if (m<0)
{
m = noOfCols-1;
n--;
}
}
}
You can also make your own logic what you think is better for you choose that one what you want
Stay blessed.
Following code will be used to print 2D-Array
for(int i=0;i<noOfRows;i++)
{
for(int j=0;j<noOfCols;j++)
{
Console.Write(array2D[i,j]);
if(j<noOfCols-1)
{
Console.Write(",");
}
}
Console.WriteLine();
}
Result:
0,1,2,3,4,5
6,7,8,9,a,b
c,d,e,f,g,h
i,j,k,l,m,n
o,p,q,r,s,t
u,v,w,x,y,z