I am fighting with this puzzle - there are two errors where I got stuck.
Here’s my source code
public class Solution {
public string IntToRoman(int num) {
Dictionary<Int32, String> romanMap = new Dictionary<int, String>
{
{ 1000, "M" },
{ 900, "CM" },
{ 500, "D" },
{ 400, "CD" },
{ 100, "C" },
{ 90, "XC" },
{ 50, "L" },
{ 40, "XL" },
{ 10, "X" },
{ 9, "IX" },
{ 5, "V" },
{ 4, "IV" },
{ 1, "I" },
};
String res = (0).ToString();
//this line below gives me the two errors
for(String index = (num.Length - 1).ToString(), last = 0; index >= 0; index--){
String current = romanMap[num[index]];
res += (current < last ? -current : current);
last = current;
}
return res;
}
}
Here are my errors
Line 21: Char 33: error CS1061: 'int' does not contain a definition for 'Length' and no accessible extension method 'Length' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?) (in Solution.cs)
Line 21: Char 64: error CS0029: Cannot implicitly convert type 'int' to 'string' (in Solution.cs)
I have tried applying (int).ToString or switching the Length to Count method, however I could not resolve these errors. Any hints pretty much appreciated!