Looking to implement a switch case statement method inside a class. I have a class that I'm writing to from a SQL select and sql datareader. Having trouble setting up the Status class which I pass in a string to it and it returns the corresponding string result and saves it to appstatus. I can't add the break after each case because I receive unreachable code detected. Now I'm getting this error: Error- member names cannot be the same as their enclosing type
public class SampleData
{
public SampleData()
{
}
public string name { get; set; }
public string phoneNbr { get; set; }
public Status appstatus { get; set; }
}
public class Status
{
public Status() { }
public string Status(string l)
{
switch (l)
{
case "A":
return "Yes";
case "B":
return "No";
case "C":
return "Okay";
case "D":
return "Maybe";
case "E":
return "Need More Info";
default:
return ("Unknown");
}
}
}
Here is where I access the class and write to it from a SQL select.
...using (SqlDataReader read = cmd.ExecuteReader())
{
while (read.Read())
{
try
{
SampleData d1 = new SampleData();
d1.name = Convert.ToString(read["..."]);
d1.phoneNbr = Convert.ToString(read["..."]);
d1.appstatus = new Status(Convert.ToString(read["..."]).Trim());
list.Add(d1);
}
}
}