我的C#编程简单代码 [英] my simple code of c# programming
本文介绍了我的C#编程简单代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace multithreading
{
class Program
{
static void Main(string[] args)
{
int[] numbers = new int[1001];
for (int i = 0; i < 1000; i++)
{
numbers[i] = i;
Console.WriteLine(numbers);
}
Console.ReadKey();
}
}
}
此代码无法正常工作.如果我将console.writeline(number)更改为console.writeline(i),它将起作用.为什么?
this code is not work properly.if i change console.writeline(number) to console.writeline(i)it will work.why?
推荐答案
尝试并放入
Try and put
numbers.ToString();
,然后
numbers(i).ToString();
,您会看到原因.
您还可以使用String.Join
来写出整个数组:
http://msdn.microsoft.com/en-us/library/57a79xd0.aspx [ ^ ]
and youll see why.
You could also use String.Join
to write out your entire array:
http://msdn.microsoft.com/en-us/library/57a79xd0.aspx[^]
如果添加Console.writeline(numbers [i])则可以正常工作,或者即使您将console.writeline(i)也可以打印数字.
因为您使用的是for循环,其中变量i持有值,并且同时您不能仅使用名称本身来访问数组变量.您还需要在其中循环变量.
我想你已经澄清了.
编码愉快.
if adding Console.writeline(numbers[i]) it can work or even if you put console.writeline(i) also it print the number.
because you are using for loop where variable i is holding value, and at the same time you can''t access array variable with simply name itself. You also need looping variable inside in it.
I think you got clarification.
Happy coding.
因为数字是int数组的对象.它是一个int类型数据的集合.
所以你写数字[i].
Because number is the object of int array. its a collection of int type data.
so you write number[i].
这篇关于我的C#编程简单代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文