Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Use of ternary operator for typecasting

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 185
    Comment on it

    While writing codes you need to convert it according to your requirement

     

    For doing that you can do typecasting of the operands

     Public Function GetFriendsToNudge(ByVal accessToken As String) As UsersResponse
            Dim reader As SqlDataReader
            Dim users As New Users()
            Dim usersResponse As New UsersResponse()
    
            Try
                Using sqlConnection As New SqlConnection(ConnectionString)
                    If sqlConnection.State = ConnectionState.Closed Then
                        sqlConnection.Open()
                    End If
    
                    Dim parameterList As New List(Of SqlParameter)()
                    parameterList.Add(New SqlParameter("@AccessToken", accessToken))
    
                    reader = BaseRepository.ExecuteReader(sqlConnection, CommandType.StoredProcedure, "uspGetFriendsToNudge", parameterList.ToArray())
    
                    If reader.HasRows Then
                        While reader.Read()
    
                            users.users.Add(New User() With {
                                .Id = If(reader("ID") IsNot Nothing, If(Not String.IsNullOrEmpty(Convert.ToString(reader("ID"))), Convert.ToInt32(Convert.ToString(reader("ID")).Trim()), 0), 0),
                                .FullName = If(reader("Friend") IsNot Nothing, Convert.ToString(reader("Friend")).Trim(), String.Empty)
                            })
    
                        End While
    
                        usersResponse.Status = True
                        usersResponse.Message = "Friends successfully fetched."
                    Else
                        usersResponse.Status = False
                        usersResponse.Message = KnownConstants.UnauthorizedMessage
                    End If
                End Using
            Catch ex As Exception
                Logger.LogException(ex)
    
                usersResponse.Status = False
                usersResponse.Message = "Error occurred while getting friends."
            End Try
    
            usersResponse.data = users
            Return usersResponse
        End Function
    

    In this code type conversion and checking both are done at the coding end using ternary operators

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: