What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 23024 |  Welcome, Guest!   Register  Login
 Home > Coding Horrors > Pattern and Practices > Solve function X ...
Pbethi1984

Solve function X

 Coding Horror posted by: Pbethi1984 | Posted on: 4/6/2012 | Category: Pattern and Practices | Views: 1969 | Level: Starter | Status: [Member] | Points: 75 | Alert Moderator   



Please any one of  you answer the below question .

 

1.       Analyse FunctionX (Below) and describe what the function does.

    'InputParam is a collection of integers

    Public Function FunctionX(ByVal InputParam As Collection) As Integer

        Dim returnVal As Integer

 

        If (InputParam.Count > 0) Then

 

            'The enumerator object allows you to traverse the collection

            Dim collectionEnum As IEnumerator

            collectionEnum = InputParam.GetEnumerator()

 

            Dim int1 As Integer = 0

            Dim int2 As Integer = 0

            While (collectionEnum.MoveNext())

 

                int2 = CType(collectionEnum.Current, Integer)

 

                If int2 > int1 Then

                    int1 = int2

                End If

 

            End While

 

            returnVal = int1 + 1

        Else

            returnVal = 0

        End If

        Return returnVal

    End Function

 



Found interesting? Add this to:


Experience:0 year(s)
Home page:http://www.dotnetfunda.com
Member since:Friday, April 06, 2012
Level:Starter
Status: [Member]
Biography:
 Responses
Mani5155
Posted by: Mani5155 | Posted on: 4/10/2012 | Level: Starter | Status: [Member] | Points: 15 | Alert Moderator 

it simply return the last enumerator largest integer value plus one to the calling method if input collection doesn`t contain any value then it return 0 to calling method

<iframe src="https://www.mcpvirtualbusinesscard.com/VBCServer/manivannanm/interactivecard"/>

Anu.Malik
Posted by: Anu.Malik | Posted on: 7/4/2012 | Level: Starter | Status: [Member] | Points: 15 | Alert Moderator 

Hi,

Then purpose of FunctionX is fetch the largest value from collection and return the largestvalue increment with 1.

How It work ....
FunctionX recieve a collection InputParam.
If (InputParam.Count > 0) Then==>First Check the length of this collection

Dim collectionEnum As IEnumerator ==>Create collectionEnum object IEnumerator type
collectionEnum = InputParam.GetEnumerator()==>Get all elements From Collection and set in collectionEnum
Dim int1 As Integer = 0

Dim int2 As Integer = 0

While (collectionEnum.MoveNext()) ==> Loop for fetching all element and traverse loop at to end of collection


int2 = CType(collectionEnum.Current, Integer)==> fetch currect element and set value in int2
If int2 > int1 Then ==> If currect value is > Previous value , First time int1 is 0

int1 = int2 ==>Set large value in int1

End If

End While
returnVal = int1 + 1 ==> return value will be LargeValue +1

Else

returnVal = 0 ==> If collection has no element then return 0

End If

Return returnVal ==> return final value

End Function



Thanks & Regards ,
Anu Malik

Sinha.Rajeshk
Posted by: Sinha.Rajeshk | Posted on: 8/9/2012 | Level: Starter | Status: [Member] | Points: 15 | Alert Moderator 

This function checks if there is element in the collection it adds 1 to the largest element in the collection and returns the same otherwise returns 0.

>> Write Response - Respond to this post and get points

More Coding Horrors

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/22/2013 2:56:02 PM