测试数组元素变更
SqlCommand cmd; SqlCommand[] cmds, cmds1; cmds=new SqlCommand[10]; cmds1=new SqlCommand[10]; for (int i = 0; i < 10; i++) { cmd = new SqlCommand("select * from dbo.table" + i.ToString()); cmds[i] = cmd; cmd=new SqlCommand("select * from hr.table"+i.ToString()); cmds1[i] = cmd; } Console.WriteLine("打印cmds"); for (int i = 0; i < 10; i++) { Console.WriteLine("cmds"+i.ToString()+":"+cmds[i].CommandText.ToString()); } Console.WriteLine("打印cmds1"); for (int i = 0; i < 10; i++) { Console.WriteLine("cmds1" + i.ToString() + ":" + cmds1[i].CommandText.ToString()); } Console.WriteLine(); Console.ReadKey();
打印cmds cmds0:select * from dbo.table0 cmds1:select * from dbo.table1 cmds2:select * from dbo.table2 cmds3:select * from dbo.table3 cmds4:select * from dbo.table4 cmds5:select * from dbo.table5 cmds6:select * from dbo.table6 cmds7:select * from dbo.table7 cmds8:select * from dbo.table8 cmds9:select * from dbo.table9 打印cmds1 cmds10:select * from hr.table0 cmds11:select * from hr.table1 cmds12:select * from hr.table2 cmds13:select * from hr.table3 cmds14:select * from hr.table4 cmds15:select * from hr.table5 cmds16:select * from hr.table6 cmds17:select * from hr.table7 cmds18:select * from hr.table8 cmds19:select * from hr.table9