public test[] mytest = new test[128]; mytest[0] = "xxxxx"; mytest[1] = "xxxxx"; mytest[2] = "xxxxx";}
1. public test[] mytest = new test[128]{1,2,3,4...};2. public void Method() { for(int i = 0; i < mytest.Length; i++) { mytest[i] = "XX"; } } 3. public void Method() { mytest[0] = "aa"; mytest[1] = "bb"; }
看: //初始化一维数据 int[] a1 = new int[2];//默认值为0; int[] a2 = new int[]{1,2}; //初始化等长二维数据 int [,] ab1 = new int [2,3];//默认值为0; int [,] ab2 = new int [2,3]{{1,2,3},{4,5,6}}; //初始化不等长二维数据 int [][] abc = new int [2][]; abc[0] = new int[]{1,2}; abc[1] = new int[]{3,4,5,6};//一步步初始化更有助于理解; string[][] ColumnName = new string[3][]; ColumnName[0] = new string[1] { "aaa"}; ColumnName[1] = new string[] {"aaa","bbb" }; ColumnName[2] = new string[3] {"aaa","bbb","ccc" };
可能是我没说清楚吧 class test { int i; string s;
public test[] mytest = new test[128] {???} } 比如我现在有两组数据,i = 2, s = "fdfdfs"和i = 3, s = "bkehi" 那么我应该在{???}中怎么样一次性的进行赋值?
public object[][] test() { object[][] tmp = new object[][] { new object[] { "2", "fdfdfs" }, new object[] { "3", "bkehi" } }; return tmp; }
... 你直接这么写吧 object[][] tmp = new object[][] { new object[] { "2", "fdfdfs" }, new object[] { "3", "bkehi" } };
{
int i;
string s;
public test[] mytest = new test[128];
mytest[0] = "xxxxx";
mytest[1] = "xxxxx";
mytest[2] = "xxxxx";}
public test[] mytest = new test[128]{1,2,3,4...};2.
public void Method()
{
for(int i = 0; i < mytest.Length; i++)
{
mytest[i] = "XX";
}
}
3.
public void Method()
{
mytest[0] = "aa";
mytest[1] = "bb";
}
//初始化一维数据
int[] a1 = new int[2];//默认值为0;
int[] a2 = new int[]{1,2};
//初始化等长二维数据
int [,] ab1 = new int [2,3];//默认值为0;
int [,] ab2 = new int [2,3]{{1,2,3},{4,5,6}};
//初始化不等长二维数据
int [][] abc = new int [2][];
abc[0] = new int[]{1,2};
abc[1] = new int[]{3,4,5,6};//一步步初始化更有助于理解;
string[][] ColumnName = new string[3][];
ColumnName[0] = new string[1] { "aaa"};
ColumnName[1] = new string[] {"aaa","bbb" };
ColumnName[2] = new string[3] {"aaa","bbb","ccc" };
class test
{
int i;
string s;
public test[] mytest = new test[128]
{???}
}
比如我现在有两组数据,i = 2, s = "fdfdfs"和i = 3, s = "bkehi"
那么我应该在{???}中怎么样一次性的进行赋值?
{
object[][] tmp = new object[][] { new object[] { "2", "fdfdfs" }, new object[] { "3", "bkehi" } };
return tmp;
}
你直接这么写吧
object[][] tmp = new object[][] { new object[] { "2", "fdfdfs" }, new object[] { "3", "bkehi" } };