//如下代码供参考.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSCONSOLE
{
class Program
{
static void OutputStrings(string[][] str,int row)
{
for (int i = 0; i < row; i++)
{
foreach (string s in str[i])
Console.WriteLine(s);
}
}
static void OutputStrings(string[] str1)
{
foreach (string s in str1)
Console.WriteLine(s);
}
static void OutputStrings(string[,] str2)
{
foreach (string s in str2)
Console.WriteLine(s);
}
static void Main(string[] args)
{
//锯齿数组创建方式一
string[][] col1 = new string[3][];
col1[0] = new string[] { "aaa" };
col1[1] = new string[] { "bbb" ,"ccc"};
col1[2] = new string[] { "ddd", "eee", "fff" };
//锯齿数组创建方式二
string[][] col2 = new string[2][]
{
new string[]{"aa"},
new string []{"bb"}
};
OutputStrings(col1,3);
OutputStrings(col2,2);
//一维数组
string[] str1 = new string[] { "abc", "def" };
OutputStrings(str1);
//二维数组
string[,] str2 = new string[,] { {"aa", "bb"}, {"cc", "dd" }};
OutputStrings(str2);
Console.ReadKey();
}
}
}
温馨提示:答案为网友推荐,仅供参考