You write the following code to implement the BraindumpsClass.MyMethod function. Public Class NewClass

You write the following code to implement the BraindumpsClass.MyMethod function.
Public Class NewClass
Public Function MyMethod(ByVal Arg As Integer) As Integer
Return Arg
End FunctionEnd Class You need to call the BraindumpsClass.MyMethod function
dynamically from an unrelated class in your assembly. Which code segment should you use?

A. Dim objNewClass As New NewClassDim objType As Type =
    objNewClass.GetTypeDim objInfo As MethodInfo = _
    objType.GetMethod("MyMethod")Dim objParams() As Object = {1}Dim i As Integer =
    _
    DirectCast(objInfo.Invoke(Me, objParams), Integer)
B. Dim objNewClass As New NewClassDim objType As Type =
    objNewClass.GetTypeDim objInfo As MethodInfo =
    objType.GetMethod("MyMethod")Dim objParams() As Object = {1}Dim i As Integer =
    _
    DirectCast(objInfo.Invoke(objNewClass, objParams), Integer)
C. Dim objNewClass As New NewClassDim objType As Type =
    objNewClass.GetTypeDim objInfo As MethodInfo = _
    objType.GetMethod("NewClass.MyMethod")Dim objParams() As Object = {1}Dim i As
    Integer = _
    DirectCast(objInfo.Invoke(objNewClass, objParams), Integer)
D. Dim objType As Type = Type.GetType("NewClass")Dim objInfo As MethodInfo =
    objType.GetMethod("MyMethod")Dim objParams() As Object = {1}Dim i As Integer =
    _
    DirectCast(objInfo.Invoke(Me, objParams), Integer)


Answer: B 

No comments:

Post a Comment