我有一个for循环,把数据放到数组里,怎么在for循环外面取到数组的值

我有一个for循环,把数据放到数组里,怎么在for循环外面取到数组的值,第1张

在for外面声明就可以了

String iArray[] = new String[7]

for(Element BASE_PART:listbase){

........

iArray[] = {name,sex,idnum,bdate,vtype,hnum,vid}

}

int[] array1 = new int[10]

Console.WriteLine("向数组输入十个学生的成绩:")

for (int i = 0i <array1.Lengthi++)

{

array1[i] = int.Parse(Console.ReadLine())

}

for (int j = 0j <10j++)

{

Console.WriteLine("第{0}个学生的成绩为:{1}", j, array1[j])

}

Console.ReadLine()

这样写才可以

for (int i = 0i <10i++)

{

SqlDataReader reader = null

SqlCommand cmd = conn.CreateCommand()

cmd.CommandText = "Select Answer from Question where QuestionId=@QUESTIONID"

cmd.Parameters.Add(new SqlParameter("@QUESTIONID", question[i]))

reader = cmd.ExecuteReader()

while (reader.Read())

{

ans[i] = reader.GetValue(0).ToString()

}

reader.Close()

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/8004005.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-12
下一篇 2023-04-12

发表评论

登录后才能评论

评论列表(0条)

保存