Home > Mobile >  Converting int value to string value in list usage
Converting int value to string value in list usage

Time:03-21

I need to convert the int value that says "1" to string value as below, but I don't know, I'm using new Microsoft Visual Studio so I don't know much about List<>, I would appreciate your help.

 List<string> cities = new List<string>();
cities.Add("Ankara");
cities.Add("Adana");


cities.Add("İstanbul");


cities.Add(1);    
cities.Add('A');

CodePudding user response:

You could just to val.ToString(). (val in this case is whatever value that you will be adding in)

...
int value = 1
string str_val = value.ToString()
cities.Add(str_val)
  •  Tags:  
  • c#
  • Related