How to use reflection to call generic method?
Answer / Deependra Verma
"To use Reflection to call a generic method, first obtain the Type object of the generic type, then create an instance of MethodInfo for the desired method using MakeGenericMethod(). Next, create an instance of the target type and call the method using Invoke(). Here is an example:nn```csharpnType genericType = typeof(List<>);nMethodInfo methodInfo = genericType.MakeGenericMethod(typeof(int));nobject obj = Activator.CreateInstance(genericType);nobject result = methodInfo.Invoke(obj, new object[] {});n``
| Is This Answer Correct ? | 0 Yes | 0 No |
What is difference between private and static constructor?
What are STA And MTA in threading?
What is float in unity?
What is the difference between writeline and write in c#?
What are console applications used for?
Is it possible to implement an interface to a structure? Is it possible to extend a struct? Is it possible to inherit a class to struct?
9 Answers IBM, Logica CMG, TCS,
How do I register my code for use by classic com clients?
what is uniary operators and binary operators and what is the difference
What is routing in c#?
In which way a two-dimensional array declared in C#?
What?s the advantage of using System.Text.StringBuilder over System.String?
What is boxing? Explain its functionality?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)