Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4618368
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:15:25+00:00 2026-05-22T02:15:25+00:00

My code is like the below one, public object GetObjectValue(object obj, int condition) {

  • 0

My code is like the below one,

public object GetObjectValue(object obj, int condition)
{
     if(condition > 10)
     {
       //exit from method 
       // return; gives compiler error.      
     }
     else
     {
        GetObjectValue(obj,condition); // like this i need to use recursive call.
        //Do stuffs
     }
}

How to exit from this method. Help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:15:26+00:00Added an answer on May 22, 2026 at 2:15 am

    Some points:

    1. You need to return something in either case. Even if you return null on if(condition > 10), your next compilation error will say you need to return a value on every path (actually, that’s the same compilation error)
    2. GetObjectValue(obj,condition); may result in an infinite recursion – you call it with the same values over and over.
    3. You cannot “do stuff” after a return statement – that marks the end of the executed code (unless you have a finally block, but that’s another subject). If you don’t want to return that value that’s also great, but you probably want to use it somehow: object returnedValue = GetObjectValue(obj, condition);

    You may be looking for something like:

    public object GetObjectValue(object obj, int condition)
    {
         if(condition > 10)
         {
           //exit from method 
           return null; 
         }
         else
         {
            IChild current = (IChild)obj
            //Do stuffs HERE
            return GetObjectValue(current.Parent, condition + 1);  recursive call.
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In another question on SO I answered with code like the one below and
I met an interesting issue about C#. I have code like below. List<Func<int>> actions
The code looks like below: namespace Test { public interface IMyClass { List<IMyClass> GetList();
I rewrite my old code in new style, like below: #old style open(FD,file); #new
I would like to know how to modify the below code to strip =20
I'd like to take XML in the format below and load each code record
I have a Nationality ComboBox like the one below and want to make it
i have code like below. Base is the base class and D1, D2, D3
Code like this often happens: l = [] while foo: # baz l.append(bar) #
I have some code like this in a winforms app I was writing to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.