0
Converting Variables
An error popped up when I entered in this code: SortedList<string,int> test = new SortedList<string,int>(); string score = Console.ReadLine(); Convert.ToInt32(score); test.Add("Anna",score); It said that I couldn't convert string to integer even though I have the conversion statement in the code. When I leave the code at the conversion statement, it just says "No output" like there's nothing wrong with the code, but as soon as that variable is used in any way, there's an error. I have no idea what I did wrong here.
2 Respuestas
+ 3
Convertion statement returns converted value. You should store that in a variable.
It can't modify original.
int st=Convert.ToInt32(score);
test.Add("Anna",st);
+ 4
Or just move it inside the Add() call
test.Add("Anna", Convert.ToInt32(score));