You write the following code to implement the BraindumpsClass.MyMethod function.
public class BraindumpsClass {
public int MyMethod(int arg) {
return arg;
}}
You need to call the BraindumpsClass.MyMethod function dynamically from an unrelated class in your assembly. Which code segment should you use?
A. BraindumpsClass^ myClass = gcnew BraindumpsClass();Type^ t = BraindumpsClass::typeid;
MethodInfo^m = t->GetMethod(“MyMethod”);
int i = (int)m->Invoke(this, gcnew array<Object^> {1});
B. BraindumpsClass^ myClass = gcnew BraindumpsClass();Type^ t = BraindumpsClass::typeid;
MethodInfo^m = t->GetMethod(“MyMethod”);
int i = (int)m->Invoke(myClass, gcnew array<Object^> {1});
C. BraindumpsClass^ myClass = gcnew BraindumpsClass();
Type^ t = BraindumpsClass::typeid;
MethodInfo^m = t->GetMethod(“BraindumpsClass.MyMethod”);
int i = (int)m->Invoke(myClass, gcnew array<Object^> {1});
D. Type^ t =Type::GetType(“BraindumpsClass”);
MethodInfo^m = t->GetMethod(“MyMethod”);
int i = (int)m->Invoke(this, gcnew array<Object^> {1});
Answer: B
public class BraindumpsClass {
public int MyMethod(int arg) {
return arg;
}}
You need to call the BraindumpsClass.MyMethod function dynamically from an unrelated class in your assembly. Which code segment should you use?
A. BraindumpsClass^ myClass = gcnew BraindumpsClass();Type^ t = BraindumpsClass::typeid;
MethodInfo^m = t->GetMethod(“MyMethod”);
int i = (int)m->Invoke(this, gcnew array<Object^> {1});
B. BraindumpsClass^ myClass = gcnew BraindumpsClass();Type^ t = BraindumpsClass::typeid;
MethodInfo^m = t->GetMethod(“MyMethod”);
int i = (int)m->Invoke(myClass, gcnew array<Object^> {1});
C. BraindumpsClass^ myClass = gcnew BraindumpsClass();
Type^ t = BraindumpsClass::typeid;
MethodInfo^m = t->GetMethod(“BraindumpsClass.MyMethod”);
int i = (int)m->Invoke(myClass, gcnew array<Object^> {1});
D. Type^ t =Type::GetType(“BraindumpsClass”);
MethodInfo^m = t->GetMethod(“MyMethod”);
int i = (int)m->Invoke(this, gcnew array<Object^> {1});
Answer: B
No comments:
Post a Comment