Alternative way of implementation of a code

Posted by vikramjb on Stack Overflow See other posts from Stack Overflow or by vikramjb
Published on 2010-05-17T12:51:36Z Indexed on 2010/05/19 11:10 UTC
Read the original article Hit count: 286

Filed under:
|

The title is not exactly meaningful, but I am not share what else to name it. I wrote a TOC Generation code sometime later. Based on this I was writing code to check for duplicates also. The code is as follows

curNumber = getTOCReference(selItem.SNo, IsParent);
CheckForDuplicates(curNumber, IsParent,out realTOCRef);
curNumber = realTOCRef;

And the code for CheckForDuplicates is

        ListViewItem curItem = this.tlvItems.FindItemWithText(curNumber);

        if (curItem != null)
        {
            curNumber = this.getTOCReference(curNumber, !IsParent);
            CheckForDuplicates(curNumber, IsParent,out realTOCRef);
        }
        else
        {
            realTOCRef= curNumber;
        }

What this code does, it gets a TOC and tries it find if it already exists in the ObjectListView and gets a new TOC if there is a existing TOC. Once it determines that the generated TOC is not there in the list it stores it in realTOCRef and sends it back to the main calling code.

I have used "out" to return the last generated TOC, which is something I did not want to do. The reason why I did it was after the non duplicate TOC was generated the return was not going back to the calling code instead it looped through the previous instances then it returned back. When the looping back happened the TOC that was to be returned also got reset.

I would appreciate any help on this.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET