[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: simple, array question!

Lloyd Linklater

9/4/2008 1:39:00 PM

hwang is wrote:
> hi! Gentlemen
>
> i don't understand array declaration..
>
> c languages, array declaration is...
>
> char str[100];
>
> but, how do i declaration an array for ruby..
>
> oo is difficult...
>
> plz teach me ..

To get a specific size of array, you specify the number of items.

ar = Array.new(100)
p ar.length
=> 100

Also, you can specify how to initialize the array.

n = 5
ar = Array.new(n, "A")
n.times {|i| p i, ar[i]}

results in:

0
"A"
1
"A"
2
"A"
3
"A"
4
"A"

I hope that helps.
--
Posted via http://www.ruby-....