- Code: Select all
class Prog
def main
print .add([1, 2, 3], 4)
def add(a as List<of int>, b as int) as List<of int>
r = []
for v in a
v = v + b
r.add(v)
return r
gives me the error:
Cannot implicitly convert type "System.Collections.Generic.List<object>" to "System.Collections.Generic.List<int>"
Somehow I need to tell the compiler that 'r' is a list of ints when I initialize it. Because when I change the above to 'r = [2]' (or any other int in place of 2) it works. I tried 'r = int[]' but that didn't seem to work. Also did not find anything on how to set the type of an empty list on this page: http://cobra-language.com/how-to/UseLists/
Thanks for any help you can provide.