Can not convert type "string" to "int"

0
<%
        foreach (System.Collections.DictionaryEntry entry in HttpContext.Current.Cache){
            HttpContext.Current.Cache.Remove((string)entry.Key);
        }

            foreach (int key in diamondMethodList)
            {

                Response.Write(string.Format("<option value=\"{0}\">{1}</option>", key, diamondMethodList[key]));
            }
        %>

Hello, I have a small error in foreach, how do I convert? if I change the int key to string key it gives the following error in diamondMethodList [key]: can not implicitly convert type "string" to "int"

    
asked by anonymous 24.05.2018 / 17:20

1 answer

0

HOW TO CONVERT STRING TO INT?

// Simples String para int
static void Main(string[] args)
{
    String text = "10";
    int a = Convert.ToInt32(text);
    int b = 10;
    int result = a + b;
    Console.WriteLine("Resultado: " + result);
    Console.ReadKey();
}

The output of the Console Application:

Resultado: 20
    
25.05.2018 / 08:54