Home > DeveloperSection > Forums > Unreachable Code Detected Return Value
Pravesh Singh
Pravesh Singh

Total Post:101

Points:709
Posted on    May-15-2013 8:00 AM

 C# C# 
Ratings:


 1 Reply(s)
 720  View(s)
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 


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    May-15-2013 8:49 AM

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;
    }
}

Don't want to miss updates? Please click the below button!

Follow MindStick