Click here to Skip to main content
12,505,591 members (54,942 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: 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();
 
        }
    }
}
this code is not work properly.if i change console.writeline(number) to console.writeline(i)it will work.why?
Posted 7-Oct-12 22:44pm
Updated 7-Oct-12 22:46pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try and put
numbers.ToString();
and then
numbers(i).ToString();
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[^]
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Because number is the object of int array. its a collection of int type data.
so you write number[i].
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Hi,

you can try the following syntax. May be it help you.

Console.WriteLine(numbers[i]);

Thanks,
Viprat
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160927.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100