public int getRandomID ()

         Random r = new Random();
         return r.Next(10000,99999);

         string value = ddlCType.SelectedItem.Value;

         switch (value)
             case "Men Formal":
                 return "KML"+r;

i get an error Cannot implicitly convert type string to int in return "KML"+r;
how to solve it?

Edited by ~s.o.s~: Moved to an appropriate forum

5 Years
Discussion Span
Last Post by ChrisHunter

"KML" isn't a meaningful integer value. Presumably since the ID cannot work as an int, your only option is to return a string.:

public string getRandomID()

The function also doesn't return a value in all execution paths. What if value doesn't match "Men Formal"?


Int can't store anything but numeric values. If your string is made of ONLY numeric values you can convert it like so:

int MyInt = Convert.ToInt32("1234");

But you CAN NOT do:

int MyInt = Convert.ToInt32("Chris 1234");

Have a look at this link, it will explain the different data types and how they work

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.