Click here to Skip to main content
Rate this: bad
good
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 23:44pm
Edited 7-Oct-12 23: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
0 OriginalGriff 390
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,260


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2014
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