--------------enigC6C0316FF5D06DBA5146AD50 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable donn / cmscms.com wrote: > C#, in my opinion, is garbage trying to smell sweet. Especially in therea of arrays. And here is where I solicit from you your best C# > practice to emulate Ruby. It's a simple matter of how big an array is.In Ruby, I elegantly add member to an array using "a << 'something'." > It knows how many elements there are simply by adding. When I want to > use the elements, I elegantly code "a.each{|x| whatever}". > Ruby Array != C# array. Ruby Array = C# ArrayList. (Sort of.) > Now, in C#, I have to declare the array of a specific type. I have to > provide a size, x. I then have to brute force assign an element to a > specific index. Made irrelevant by the above. Learn C# before criticising it. > And if I want to use the elements of the array, I use > a foreach statement. And because it is a statement, I have to declare > the type of receiving variable because foreach doesn't know the type ofrray. That has nothing to do with the fact it's a statement. AFAIK, C# 3.0 will have type inference for local variables, so you won't have to do that anymore. > And when foreach executes, it is for every element up to x, not > the number of populated elements. > That's the behaviour of ArrayList too. Ruby's Arrays compensate this with the quirk that out-of-bounds access silently returns nil. (Although I think there's a method with a stricter approach to this. > Is there and elegant way in C# to append members into an array, and > execute foreach for each populated member? Or do I have to code my ownxtensions to class array such that it acts like Ruby? Has someone > already done this in C#? > Use. ArrayLists. Changing class array won't help anything, because they're a first-class primitive datatype. Ruby doesn't have an equivalent to them, because it uses C arrays as backing storage. Also, C# 2.0 has lambdas. C# 3.0 will let you add methods to external classes. I'd be very, very surprised if there isn't a library that can do each/select/collect/inject for C# 3.0 already, unless .NET 3.0 adds that in the framework itself. I don't follow happenings in dotnetland, so I can't tell. > Once again, I can't express my appreciation enough. I'm thinking of > learning C# for my company, but still implement everything in Ruby > anyway. Hell, I can prototype production ready code in Ruby so much > faster than I can translate it to C#. > While Ruby fluffs are always welcome, accompanying them with an ill-informed rant makes them taste so bitter. And if the ill-informed rant is a flame at another programming language with a completely different audience / area of application, their value approaches zero. David Vallner --------------enigC6C0316FF5D06DBA5146AD50 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (MingW32) iD8DBQFFU53iy6MhrS8astoRAmNLAJ4y9wfTkrcAd/LvEsjeBEh38H4WUQCfV8uR Zju8WE9clyXYSUlYAt6egFg ji -----END PGP SIGNATURE----- --------------enigC6C0316FF5D06DBA5146AD50--