locked
Ctype(sender, integer) RRS feed

  • Question

  • User521359272 posted

    This is an ugly cast, but the code for this solution is already in a bad place, and it's not my job to fix. I'm curious if there is a way to determine whether a cast will be valid prior to casting.


    Dim size As Integer = CType(sender, Integer)
    
    'If cast was successful
    'pass size to DAL
    'if not pass something else



    Monday, November 29, 2010 11:07 AM

Answers

  • User1224194097 posted

    I am not sure about the TYPE of the sender, but you can check the type of the sender before converting the value to integer

    If sender.[GetType]().Equals(GetType(Integer)) Then
       'Do something for type casting here
    End If


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 29, 2010 11:51 AM
  • User2047364424 posted

        If (TypeOf sender Is Integer) Then
    
            End If



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 29, 2010 11:52 AM

All replies