c# - Why am I printing out 'System.Int32[]' instead of my array of numbers? -


i trying print out array of numbers have assigned particular array. algorithm choosing numbers consists of choosing random number not duplicate , storing inside array.

pretty simple really, have no idea why printing out error.

int[] ticket1 = new int[4]; (int = 0; < 4; i++) {     int temp = rand.next(43);     while (ticket1.contains(temp))      {         temp = rand.next(43);     }     ticket1[i] = temp; } console.writeline("{0}{1}", item.padright(20), ticket1.tostring());//ticket1 produces system.int32[] instead of 4 numbers. //i have changed line to: //console.writeline("{0}{1}", item.padright(20), string.join(",", ticket1)); //and still doesn't work. error remains. (system.int32[]) 

my question is, how can print out 4 numbers (beside each other) in string format.

//edit: i've found problem. putting ticket1 inside foreach loop, it's somehow not reaching out array values , therefore prints out system.int32[] instead.

all fixed.

if call tostring() on array that, full name of type of class.

you fix few ways. print current item inside loop, or print each item 1 @ time outside of loop:

console.writeline("{0}{1}", item.padright(20), ticket1[0]); console.writeline("{0}{1}", item.padright(20), ticket1[1]); // etc... 

or "flatten" collection before printing:

console.writeline("my numbers: ", string.join(", ", ticket1)); 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -