Welcome to Geekdojo Sign in | Join | Help

creating string list - why Python is healthier than C#

I needed a string array, so I go
string[] tags = new string[] {"python", "ruby", "good"};
 
but I also need to search for a particular string..
to get IndexOf(...) functionality, I change it to [C# v2]
List<string> tags = new List<string>(new string[] {"python", "ruby", "good"});
 
then, thinking that copying strings might not be efficient, looking further, I find that ArrayList has a very interesting static Adapter method, so I change it to
ArrayList tags = ArrayList.Adapter(new string[] {"python", "ruby", "good"});
 
this is still a lot of typing compared to doing it in python syntax
tags = ["python", "ruby", "good"]
 
short and sweet [more finger/keyboard friendly, more eye ball friendly, therefore more healthy]
 
if you are writing or reading just a few lines, its not a problem but when you are working with larger code base, the difference between the syntaxes is enough for you to wish IronPython would make Python a first class CLR language. IronPython v1 is in beta 6 now, but its v1 release would still only be a CLS consumer, not producer which means ASP.NET + IronPython is still in the distance.. :-(
 
let me know if anyone knows a shorter way of declaring and initializing a list of string in C#. thank you in advance.
Published Saturday, April 22, 2006 3:36 AM by richardhsu
Filed Under: ,

Comments

Anonymous comments are disabled