Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7860889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:28:48+00:00 2026-06-02T22:28:48+00:00

I want to know that how the methods are invoked using Reflection in c#

  • 0

I want to know that how the methods are invoked using Reflection in c# .

Here is the code i have picked from book

using System;
using System.Reflection;
class MyClass {
int x;
int y;
public MyClass(int i, int j) {
x = i;
y = j;
}
public int Sum() {
return x+y;
}
public bool IsBetween(int i) {
if((x < i) && (i < y)) return true;
else return false;
}
public void Set(int a, int b) {
Console.Write("Inside Set(int, int). ");
x = a;
      y = b;
Show();
}
// Overload set.
public void Set(double a, double b) {
Console.Write("Inside Set(double, double). ");
x = (int) a;
y = (int) b;
Show();
}
public void Show() {
Console.WriteLine("Values are x: {0}, y: {1}", x, y);
}
public void Show1() {
Console.WriteLine("Hello");
} 
}
class InvokeMethDemo {
static void Main() {
Type t = typeof(MyClass);
MyClass reflectOb = new MyClass(10, 20);
int val;
Console.WriteLine("Invoking methods in " + t.Name);
Console.WriteLine();
MethodInfo[] mi = t.GetMethods();
// Invoke each method.
foreach(MethodInfo m in mi) {
// Get the parameters.
ParameterInfo[] pi = m.GetParameters();
if(m.Name.Equals("Set", StringComparison.Ordinal) &&
pi[0].ParameterType == typeof(int)) {
object[] args = new object[2];
args[0] = 9;
args[1] = 18;
m.Invoke(reflectOb, args);
}
else if(m.Name.Equals("Set", StringComparison.Ordinal) &&
pi[0].ParameterType == typeof(double)) {
object[] args = new object[2];
args[0] = 1.12;
args[1] = 23.4;
m.Invoke(reflectOb, args);
}
else if(m.Name.Equals("Sum", StringComparison.Ordinal)) {
val = (int) m.Invoke(reflectOb, null);
Console.WriteLine("sum is " + val);
}
else if(m.Name.Equals("IsBetween", StringComparison.Ordinal)) {
object[] args = new object[1];
args[0] = 14;
if((bool) m.Invoke(reflectOb, args))
Console.WriteLine("14 is between x and y");
}
else if(m.Name.Equals("Show", StringComparison.Ordinal)) {
m.Invoke(reflectOb, null);

}
else if(m.Name.Equals("Show1", StringComparison.Ordinal)) {
m.Invoke(reflectOb, null);
}         
}
}
}
  1. Is the method invoked based on the number and type of parameters passed.If yes then Why

the Compiler does not show error as the **same statement is used to call method show and

show1**?

OR

  1. The method is invoked based on some reference value of m(MethodInfo m) and the
    number of parameters.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:28:52+00:00Added an answer on June 2, 2026 at 10:28 pm

    You can invoke the Methods using MethodBase Class.

    Invokes the method or constructor represented by the current instance, using the specified parameters.
    Refer this link Method Invoking in Reflection

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to know that when we want to use push notification service.From where
I want to know that is there any standards for defining gestures using Kinect
I am using Reflections to obtain a method from a class that is annotated
I have a WPF application that I want to launch using: Assembly.LoadFrom It works
I want to know that how voice recognition in android works? Which library it
I want to know that does apple's Push Notification Server generate new device token
I want to know that how can I add help support to my winform
i want to know that why do we add an app.config file in c#
I want to know that what will happen to my activity incase of an
I want to know that Filename1, provided by the user is the same as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.