Forums

How to create an empty local List<of String> ?

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

How to create an empty local List<of String> ?

Postby ObtuseAngle » Thu Sep 06, 2012 12:47 am

I would like to create a local List<of String> within a method, initially empty, to which I can then add items from information extracted from an Oracle database.

So far I've got:
Code: Select all
returnList as List<of String> = ["junk"]
returnList.clear
which works but seems somewhat clunky.

I'm still not very familiar with .NET - what am I missing?
All the other alternatives I've tried end up with a List<of object>, but I'd like to be clear that it only contains strings.
99 programming bugs in the code, 99 bugs in the code, fix 1 bug and compile it again, 101 programming bugs in the code
ObtuseAngle
 
Posts: 42
Location: Gippsland, Australia

Re: How to create an empty local List<of String> ?

Postby Charles » Thu Sep 06, 2012 1:47 am

list = List<of String>()
list.add('foo')
assert list.count == 1
trace list

# if you already have something enumerable from which
# your list derives, then you can use a for-expression:
records = .fetch('select Name from Customer where Balance > 0')
names = for record in records get record['Name']
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: How to create an empty local List<of String> ?

Postby hopscc » Thu Sep 06, 2012 1:54 am

The current kludgy answer is

returnList = List<of String>()


See this forum discussion

Theres a ticket:230 for this also which includes a pending patch
Maybe it'll get applied for the next release....
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: How to create an empty local List<of String> ?

Postby ObtuseAngle » Sun Sep 09, 2012 9:28 pm

Many thanks!

While I like the look of the suggested enhancement, the current syntax is still better than my clumsy workaround.
99 programming bugs in the code, 99 bugs in the code, fix 1 bug and compile it again, 101 programming bugs in the code
ObtuseAngle
 
Posts: 42
Location: Gippsland, Australia


Return to Discussion

Who is online

Users browsing this forum: No registered users and 38 guests

cron