forum

home / developersection / forums / only one return() for the entire method

Only one return() for the entire method

Anonymous User 1825 13-Nov-2013

I want a single return statement instead of having a return statement in each if statement. Can anybody tell me how to do it?

public object GetHeaderInfo(string agentId, string headerName) 
 {
     if (headerName =="flyer")
     {
        var headerInfo = Service.GetFlierHeaderInfo(agentId);
        // headerinfo is of type Flier object
        return headerInfo;
     }
     if (headerName == "general")
     {
         var headerInfo = Service.GetHeaderInfo(agentId);
         // headerinfo is of type report object
         return headerInfo;
     }
     return 0;
 }

c# c# 
Updated on 13-Nov-2013

I am a content writter !

Can you answer this question?

Answer

1 Answers

Liked By