UNREACHABLE CODE DETECTED RETURN VALUE

Pravesh Singh

Total Post:101

Points:709
Posted by  Pravesh Singh
C# 
C#
 1053  View(s)
Ratings:
Rate this:
Hi Guys

How to return value with this issue? Help me please.

protected string SendState(Object ID_DIP,Object ID_SEQ,Object MODUL)
{
    try
    {
        ViewState["ssDIP"] = ID_DIP.ToString();
        ViewState["ssSEQ"] = ID_SEQ.ToString();
        ViewState["ssMOD"] = MODUL.ToString();

        return ID_DIP.AsString();
        return ID_SEQ.AsString();
        return MODUL.ToString();
    }
    catch (Exception)
    {
        return "";
    }
}


Thanks 
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Unreachable Code Detected Return Value

    Hi Pravesh!

    You have multiple return statements, your code will not execute statements after first return statement. You can't return multiple values from your method, if you want to return multiple values you can either return List<string> for your case or create a temporary class and return its object.

    In your code you are using AsString, I think you probably meant ToString

    Define a class like:

    public class MyReturnObject
    {
        public string ID_DIP { get; set; }
        public string ID_SEQ { get; set; }
        public string MODUL { get; set; }
    }

    Modify your method like:

    protected MyReturnObject SendState(Object ID_DIP, Object ID_SEQ, Object MODUL)
    {
        try
        {
            ViewState["ssDIP"] = ID_DIP.ToString();
            ViewState["ssSEQ"] = ID_SEQ.ToString();
            ViewState["ssMOD"] = MODUL.ToString();

            MyReturnObject obj = new MyReturnObject();
            obj.ID_DIP = ID_DIP.ToString();
            obj.ID_SEQ = ID_SEQ.ToString();
            obj.MODUL = MODUL.ToString();
            return obj;
        }
        catch (Exception)
        {
            return null;
        }
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!