简单的代码解释数组的用法 [英] simple code to explain the use of array

查看:66
本文介绍了简单的代码解释数组的用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何处理与使用数组有关的问题?

How do I approach a question that has to do with the use of an array?

推荐答案



您可以算出要存储在其中的数据类型以及需要存储的数据量,然后创建一个足以容纳它的数组.如果您不知道数据量有多大,则可以初始化一个通用列表,然后在列表上使用ToArray()方法转换为所需类型的数组.

以下每种类型的示例.
Hi,

you work out the type of data you wish to store in it and how much of that data you need to store and you create an array that is big enough to hold it. If you don''t know how big the data is, you can initialise a generic list and then use the ToArray() method on the list to convert to tyhe array of the type you want.

Eample on each type below.
// arary example
int[] arr = new int[size];





// Generic list
List<int> lst = new List<int>();
int[] = lst.ToArray();
</int></int>



戴夫



Dave


int[] arr = {10,20,30,40,50};
for(int i=0;i''<''arr.Length;i++)
{
Console.WriteLine(arr[i]);
}



这样,您可以将5个数字与单个变量一起使用.
否则,您需要5个不同的变量来打印这5个数字.



This way you can use 5 numbers with single variable.
Otherwise you needed 5 different variables to print these 5 numbers.


好的文章此处 [ ^ ]涵盖数组的基础知识.
Good article here[^] to cover basics of an array.


这篇关于简单的代码解释数组的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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