I created the following program based on an example in the Swift programming language docs:
import System.Collections.Generic
import System.Linq;
import System.Text
import System.Threading.Tasks
func GetTeamScore()->Int {
let individualScores = [75,43,103,87,12] //<-- problem is here. Doesn’t like integers. Strings okay.
var teamScore = 0
for score in individualScores {
if score>50 {
teamScore += 3
}
else {
teamScore += 1
}
}
return teamScore
}
println(GetTeamScore());
Console.ReadLine();
I get an error–Common Language Runtime detected an invalid program. However, if I change the array above to an array of strings (just enclose the integers in quotes) and of course change the program to not try to add them up, I get no errors and it works as expected. I’ve also tried changing the let
to var
and still get the error with integers.
I suspect you may have a bug or am I doing something wrong? The code (without the println and ReadLine at the end) is straight out of the Swift language guide so I would assume it would work as written. Am I mistaken?
Thanks,
Lee