Click here to Skip to main content
11,577,240 members (58,701 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#4.0
i have 2 string arrays of same length i need them to form a 2d string array with array1 in first column and array 2 in second column to get the output i used to use:
System.IO.File.WriteAllLines(@"\\Path\Output.txt", ArrayName);
this works fine for 1d array but doesn't work for 2d array

please help
Posted 28-Dec-12 3:18am
Edited 28-Dec-12 3:25am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


It doesn't work for a 2D array, because the second parameter of the WriteAllLines funtion must be a 1D array. To write a 2D array to a file, have a look at the first answer of this question:[^]
Member 9715673 at 28-Dec-12 21:47pm
Thanks, I am able to get the output in a text file now. But the orientation is not as desired. How can I get the output in a tabular format?
ProgramFOX at 29-Dec-12 3:39am
For a string[][] or a string[,]?
Member 9715673 at 7-Jan-13 5:50am
ProgramFOX at 7-Jan-13 12:31pm
Try this:
StringBuilder outputBuilder = new StringBuilder();
for (int i = 0; i < ArrayName.GetLength(0); i++)
for (int j = 0; j < ArrayName.GetLength(1); j++)
outputBuilder.Append(ArrayName[i, j]);
if (j != ArrayName.GetLength(1) - 1)
Member 9715673 at 18-Jan-13 4:20am
the entries are of variable length in both the columns
i was looking to have them arranged in a tabular manner like

Array1 Array2
wqqwqwq | eyuyuiyuy
dsdsdsds | youyuiyuiuyiuyiuy
jkljlkjlkjlkjljl | 9089898djdidkkd
even here the output is not coming as desired :(

I'm fine even if there are no separators like the === and| used here
but i do need the second column to start from the same point in every row
currently the output is jagged like this

wqqwqwq eyuyuiyuy
dsdsdsds youyuiyuiuyiuyiuy
jkljlkjlkjlkjljl 9089898djdidkkd
ProgramFOX at 18-Jan-13 11:22am
It's working fine for me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 155
1 Afzaal Ahmad Zeeshan 125
2 OriginalGriff 115
3 Richard MacCutchan 100
4 Abhinav S 90
0 OriginalGriff 820
1 Sergey Alexandrovich Kryukov 631
2 Abhinav S 528
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 365

Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100