Page 1 of 1

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

PostPosted: Thu Sep 06, 2012 12:47 am
by ObtuseAngle
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.

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

PostPosted: Thu Sep 06, 2012 1:47 am
by Charles
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']

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

PostPosted: Thu Sep 06, 2012 1:54 am
by hopscc
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....

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

PostPosted: Sun Sep 09, 2012 9:28 pm
by ObtuseAngle
Many thanks!

While I like the look of the suggested enhancement, the current syntax is still better than my clumsy workaround.