ArrayNullConditional

Public Module Extension
        <System.Runtime.CompilerServices.Extension> _
        Public Function Extend(arr As Array, index as INteger) As String
            if (arr.Length <= index) then
                return Nothing 'Could return ""
            Else
                Dim retValue as string
                if (arr(index) is nothing) then
                    return Nothing 'Could return ""
                Else
                    return arr(index)
                End If
            End if
        End Function
    End Module
Example:
Dim strArr() as string = {"Test1","Test2", Nothing}
dim NullStr = strArr.Extend(3)
dim NothingSTr = strArr.Extend(2)
dim PopStr = strArr.Extend(0)
console.WriteLine(NullStr)
console.WriteLine(NothingSTr)
console.Writeline(PopStr)

Description

Checks the item in the array. If the index passed in is equal to size or larger than array NOTHING is returned. Otherwise returns STRING from the array. Could easily be extended to other types/objects, just change return type on extension from string to your needs.

Details

  • Author: RJ Kelly
  • Submitted on: 2/3/2017 1:02:42 AM
  • Language: VB
  • Type: Array
  • Views: 176

Double click on the code to select all.

 

;