I have a class in aspx.cs
in that i have a function like below
public static String GetMaritalStatus(String maritalStatus)
{
if (maritalStatus == null)
return "";
String[] maritalStatuses = new String[] { "--", "Single", "Married", "Divorced", "Widowed" };
return maritalStatuses[int.Parse(maritalStatus)];
}
When this function is called I am getting
input string was not in a correct format. Error
on the line
String[] maritalStatuses = new String[] { "--", "Single", "Married", "Divorced", "Widowed" };
What can be the reason.
Edited
String marital = GetMaritalStatus(02);
String marital = GetMaritalStatus(02);
02 is integer but your function GetMaritalStatus takes argument as string
use the below code to call your function
String marital = GetMaritalStatus("02");
This seems to happen on
return maritalStatuses[int.Parse(maritalStatus)];
I think 'maritalStatus' isn't an int when you try your code which gives you your error.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.