How To Put 2D Array Data To The String Variable in C# Web App?
Hi all i have a array like
string[,] terms;
if i want to put this a开发者_StackOverflowrray data to the string variable in this format string Va="23,85,69" such that 2D array have two type of data "name" and "Address" then both will get in separate string variable hopes for your reply..
string result = string.Join(",",
Enumerable.Range(0, terms.GetLength(0))
.SelectMany(i => Enumerable.Range(0, terms.GetLength(1))
.Select(j => terms[i, j])));
EDIT: Non-LINQ version:
List<string> result = new List<string>();
for (var i = 0; i < terms.GetLength(0); i++)
{
for (var j = 0; j < terms.GetLength(1); j++)
{
result.Add(terms[i, j]);
}
}
string output = string.Join(",", result);
精彩评论