从我的数组中获取输入 [英] get inputs from my array

查看:72
本文介绍了从我的数组中获取输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有这段代码,将值插入到int数组中.现在我想获取所有值.如何获取值?


在此先感谢!!

Hi all,

I have this code that inserts values into an array of int. Now i want to get all the values. How can I get the values?


Thanks in advance!!

推荐答案

您可以使用索引:
You could use the index:
int i = myArray[6];

还是您是说要遍历所有这些?在这种情况下,您有两种选择:
1)一个for循环

Or did you mean to loop through them all? In which case you have two options:
1) A for loop

int total = 0;
for (int i = 0; i < myArray.Length; i++)
   {
   total += myArray[i];
   }

2)一个foreach循环:

2) A foreach loop:

int total = 0;
foreach (int i in myArray)
   {
   total += i;
   }


还有其他方法,但是最常见.


There are other ways, but those are the most common.


让我们举个例子,数字是您在此处输入的数组.

Let''s take for example that numbers is your array of inputs here.

foreach(int number in numbers)
{
   Console.WriteLine(number);
}


如此简单,您将获得插入数组中的所有值.

问候,
爱德华


That easy, you will get all values you inserted in your array.

Regards,
Eduard


这篇关于从我的数组中获取输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆