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 8389919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:51:08+00:00 2026-06-09T18:51:08+00:00

I do apology in advance if there are many variables in the following code

  • 0

I do apology in advance if there are many variables in the following code sample that their “types” is not clear to you, it is a big library, I just can’t put all of that in here, so think of it at high-level, and the name of the variables is kind of helpful too…

Problem: A “concept” can have many “relations”. Each of those relations can also have many concepts, For example like a father and child, a father has many children, a child may itsself be a father and has more children ,etc…
So I want to pass the root father and get all the hierarchy and write it to a file …

The high-level code I am using is this, THE PROBLEM IS THAT it Crashes by a Null exception when it gets the child that has no more children. So its object is null in this line:

oUCMRConceptReltn = moTargetConceptList.ConceptReltns.get_ItemByIndex(i, false);

So I thought well let’s put a not null check around it, yeah fixes the crash BUT after it sees the first leafe, it doesn’t go further and algorithm stops.
So Something is wrong with the way I am calling recursion, but can’t figure it out.

private void MyLoadMethod(string sConceptCKI)
{
    UCMRConceptLib.UCMRConceptLoadQual oUCMRConceptLoadQual = new UCMRConceptLib.UCMRConceptLoadQual();

    //Fill out UCMRConceptLoadQual object to get new list of related concepts
    moTargetConceptList.Load(oUCMRConceptLoadQual;

    // WHEN IT IS ZERO, THERE ARE NO MORE CHILDREN.
    int numberofKids = moTargetConceptList.ConceptReltns.Count();
    if (numberofKids == 0)
        return ;
    for (int i = 1; i <= numberofKids; i++)
    {
        oUCMRConceptReltn = moTargetConceptList.ConceptReltns.get_ItemByIndex(i, false);

            //Get the concept linked to the relation concept
            if (oUCMRConceptReltn.SourceCKI == sConceptCKI)
            {
                oConcept = moTargetConceptList.ItemByKeyConceptCKI(oUCMRConceptReltn.TargetCKI, false);
            }
            else
            {
                oConcept = moTargetConceptList.ItemByKeyConceptCKI(oUCMRConceptReltn.SourceCKI, false);
            }

            //write its name to the file...now recursion: go and find its children.
            builder.AppendLine("\t" + oConcept.PrimaryCTerm.SourceString);
            MyLoadMethod(oConcept.ConceptCKI);
    }
    return ;
}
  • 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-06-09T18:51:10+00:00Added an answer on June 9, 2026 at 6:51 pm

    Just as a side note, the check for number of kids being 0 is redundant, because you’re never going to enter the loop.

    The algorithm looks okay for what you want to do. You don’t need to return anything in this case because your algorithm uses a side effect (the appendLine) to give your output.

    I don’t know C#, but it looks to me as if you’re using some variables that are not local to the function, like oUCMRConceptReltn and oConcept. If they’re not local to the function, different recursive invocations can change those values in unexpected ways. Recursive functions should almost never write to a variable outside its own scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was thinking many times, now days that we have Linq and other CLR
My Question is little bit bigger so apology for that. Now my problem is
Just want to ensure you that it is not a homework question. I am
My apology for such a noob question. On my hosting server, there are two
Firstly a forward apology: I cannot isolate the following bug into a simple console
Apple wants me to give the user a friendly apology if I can't find
Firstly, an apology for the length of this post. If brevity is the soul
Please let me preface this question with an apology. I am very new to
I have to interface with a slightly archaic system that doesn't use webservices. In
(Appology in advance if I am asking a too nwbie question. I am a

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.