---
title: "Only one return() for the entire method"  
description: "Only one return() for the entire method"  
author: "Anonymous User"  
published: 2013-11-13  
updated: 2013-11-13  
canonical: https://www.mindstick.com/forum/1716/only-one-return-for-the-entire-method  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Only one return() for the entire method

I want a single return statement [instead of](https://www.mindstick.com/articles/330/triggers-in-sql-server) having a return statement in each [if statement](https://www.mindstick.com/forum/12682/jquery-toggle-if-statement). Can [anybody tell me](https://www.mindstick.com/forum/34238/can-anybody-tell-me-what-is-the-most-useful-activity-in-seo) 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; }
```

## Replies

### Reply by Anonymous User

Hi Goti,\

Declare it at the top of your method :

```
public object GetHeaderInfo(string agentId, string headerName){    object headerInfo = 0;    if (headerName == "flyer")    {        headerInfo = Service.GetFlierHeaderInfo(agentId);    }    if (headerName == "general")    {        headerInfo = Service.GetHeaderInfo(agentId);    }    return headerInfo;}
```

The default value can be added during the initialization, it will be overwritten by any future assignation.


---

Original Source: https://www.mindstick.com/forum/1716/only-one-return-for-the-entire-method

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
