Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unreachable Code Detected Return Value

Tags:

c#

asp.net-mvc

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 "";
    }
}
like image 375
Ari Ardiansyah Avatar asked Dec 04 '25 10:12

Ari Ardiansyah


1 Answers

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;
    }
}
like image 59
Habib Avatar answered Dec 07 '25 00:12

Habib



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!