Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C# Data Types
  • C# Decision Making
  • C# Methods
  • C# Delegates
  • C# Constructors
  • C# Arrays
  • C# ArrayList
  • C# String
  • C# Tuple
  • C# Indexers
  • C# Interface
  • C# Multithreading
  • C# Exception
Open In App
Next Article:
C# | Type.GetMembers() Method
Next article icon

C# | Type.GetMethods() Method

Last Updated : 16 Dec, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
Type.GetMethods() Method is used to get the methods of the current Type. There are 2 methods in the overload list of this method as follows:
  • GetMethods(BindingFlags) Method
  • GetMethods() Method

GetMethods(BindingFlags) Method

This method is used to search for the methods defined for the current Type, using the specified binding constraints when overridden in a derived class.
Syntax: public abstract System.Reflection.MethodInfo[] GetMethods (System.Reflection.BindingFlags bindingAttr); Here, it takes a bitmask comprised of one or more BindingFlags which specify how the search is conducted or, Zero (Default), to return an empty array. Return Value: This method returns an array of MethodInfo objects representing all methods defined for the current Type which match the specified binding constraints Or an empty array of type MethodInfo, if no methods are defined for the current Type, or if none of the defined methods match the binding constraints.
Below programs illustrate the use of Type.GetMethods(BindingFlags) Method: Example 1: csharp
// C# program to demonstrate the // Type.GetMethods() Method using System; using System.Globalization; using System.Reflection;  // Defining class Empty public class Empty { }  class GFG {      // Main Method     public static void Main()     {         // Declaring and initializing object of Type         Type objType = typeof(Empty);          // try-catch block for handling Exception         try {              // Getting array of Method by             // using GetMethods() Method             MethodInfo[] info = objType.GetMethods(BindingFlags.Public | BindingFlags.Instance);              // Display the Result             Console.WriteLine("Methods of current type is as Follow: ");             for (int i = 0; i < info.Length; i++)                 Console.WriteLine(" {0}", info[i]);         }          // catch ArgumentNullException here         catch (ArgumentNullException e)         {             Console.Write("name is null.");             Console.Write("Exception Thrown: ");             Console.Write("{0}", e.GetType(), e.Message);         }     } } 
Output:
  Methods of current type is as Follow:    Boolean Equals(System.Object)   Int32 GetHashCode()   System.Type GetType()   System.String ToString()  
Example 2: csharp
// C# program to demonstrate the // Type.GetMethods() Method using System; using System.Globalization; using System.Reflection;  class GFG {      // Main Method     public static void Main()     {         // Declaring and initializing object of Type         Type objType = typeof(int);          // try-catch block for handling Exception         try {              // Getting array of Method by             // using GetMethods() Method             MethodInfo[] info = objType.GetMethods(BindingFlags.Public | BindingFlags.Static);              // Display the Result             Console.WriteLine("Methods of current type is as Follow: ");             for (int i = 0; i < info.Length; i++)                 Console.WriteLine(" {0}", info[i]);         }          // catch ArgumentNullException here         catch (ArgumentNullException e)          {             Console.Write("name is null.");             Console.Write("Exception Thrown: ");             Console.Write("{0}", e.GetType(), e.Message);         }     } } 
Output:
  Methods of current type is as Follow:    Int32 Parse(System.String)   Int32 Parse(System.String, System.Globalization.NumberStyles)   Int32 Parse(System.String, System.IFormatProvider)   Int32 Parse(System.String, System.Globalization.NumberStyles, System.IFormatProvider)   Boolean TryParse(System.String, Int32 ByRef)   Boolean TryParse(System.String, System.Globalization.NumberStyles, System.IFormatProvider, Int32 ByRef)  

GetMethods() Method

This method is used to return all the public methods of the current Type.
Syntax: public System.Reflection.MethodInfo[] GetMethods (); Return Value: This method returns an array of MethodInfo objects representing all the public methods defined for the current Type or an empty array of type MethodInfo if no public methods are defined for the current Type.
Below programs illustrate the use of the above-discussed method: Example 1: csharp
// C# program to demonstrate the // Type.GetMethods() Method using System; using System.Globalization; using System.Reflection;  // Defining class Empty class Empty { }  class GFG {      // Main Method     public static void Main()     {         // Declaring and initializing object of Type         Type objType = typeof(Empty);          // try-catch block for handling Exception         try {              // Getting array of Method by             // using GetMethods() Method             MethodInfo[] info = objType.GetMethods();              // Display the Result             Console.WriteLine("Methods of current type is as Follow: ");             for (int i = 0; i < info.Length; i++)                 Console.WriteLine(" {0}", info[i]);         }          // catch ArgumentNullException here         catch (ArgumentNullException e)          {             Console.Write("name is null.");             Console.Write("Exception Thrown: ");             Console.Write("{0}", e.GetType(), e.Message);         }     } } 
Output:
  Methods of current type is as Follow:    Boolean Equals(System.Object)   Int32 GetHashCode()   System.Type GetType()   System.String ToString()  
Example 2: csharp
// C# program to demonstrate the // Type.GetMethods() Method using System; using System.Globalization; using System.Reflection;  // Defining class Student public class Student {      private string name, dept;     private int roll;      // Constructor     public Student(string name, int roll, string dept)     {         this.name = name;         this.roll = roll;         this.dept = dept;     }      // getter for name     public string getName()     {         return name;     }      // getter for roll     public int getRoll()     {         return roll;     }      // getter for dept     public string getDept()     {         return dept;     } }  class GFG {      // Main Method     public static void Main()     {         // Declaring and initializing object of Type         Type objType = typeof(Student);          // try-catch block for handling Exception         try {              // Getting array of Method by             // using GetMethods() Method             MethodInfo[] info = objType.GetMethods(BindingFlags.Public | BindingFlags.Instance);              // Display the Result             Console.WriteLine("Methods of current type is as Follow: ");             for (int i = 0; i < info.Length; i++)                 Console.WriteLine(" {0}", info[i]);         }          // catch ArgumentNullException here         catch (ArgumentNullException e)         {             Console.Write("name is null.");             Console.Write("Exception Thrown: ");             Console.Write("{0}", e.GetType(), e.Message);         }     } } 
Output:
  Methods of current type is as Follow:    System.String getName()   Int32 getRoll()   System.String getDept()   Boolean Equals(System.Object)   Int32 GetHashCode()   System.Type GetType()   System.String ToString()  
Reference:
  • https://docs.microsoft.com/en-us/dotnet/api/system.type.getmethods?view=netframework-4.8

Next Article
C# | Type.GetMembers() Method

R

RohitPrasad3
Improve
Article Tags :
  • C#
  • CSharp-method
  • CSharp-Type-Class

Similar Reads

  • C# | Type.GetFields() Method
    Type.GetFields() Method is used to get the fields of the current Type. There are 2 methods in the overload list of this method as follows: GetFields() Method GetFields(BindingFlags) Method GetFields() Method This method is used to return all the public fields of the current Type. Syntax: public Syst
    5 min read
  • C# | Type.GetMembers() Method
    Type.GetMembers() Method is used to get the members (properties, methods, fields, events, and so on) of the current Type. There are 2 methods in the overload list of this method as follows: GetMembers() Method GetMembers(BindingFlags) Method GetMembers() Method This method is used to return all the
    4 min read
  • C# | Type.GetField() Method
    Type.GetField() Method is used to get a specific field of the current Type. There are 2 methods in the overload list of this method as follows: GetField(String) Method GetField(String, BindingFlags) Method GetField(String) Method This method is used to search for the public field with the specified
    4 min read
  • C# | Type.GetTypeCode() Method
    Type.GetTypeCode() Method is used to get the underlying type code of the specified Type. Syntax: public static TypeCode GetTypeCode (Type type); Here, it takes the type whose underlying type code to get. Return Value: This method returns the code of the underlying type, or Empty if type is null. Bel
    2 min read
  • C# | Type.GetHashCode() Method
    Type.GetHashCode() Method is used to return the hash code for this instance. Syntax: public override int GetHashCode (); Return Value: This method returns the hash code for the current instance. Below programs illustrate the use of Type.GetHashCode() Method: Example 1: // C# program to demonstrate t
    2 min read
  • C# | Type.GetMember() Method
    Type.GetMember() Method is used to get the specified members of the current Type. There are 3 methods in the overload list of this method as follows: GetMember(String) Method GetMember(String, BindingFlags) Method GetMember(String, MemberTypes, BindingFlags) Method GetMember(String) Method This meth
    6 min read
  • C# | Type.GetNestedTypes() Method
    Type.GetNestedTypes() Method is used to get the types nested within the current Type. There are 2 methods in the overload list of this method as follows: GetNestedTypes() Method This method is used to return the public types nested in the current Type. Syntax: public Type[] GetNestedTypes ();Return
    5 min read
  • C# | Type.GetEnumNames() Method
    Type.GetEnumNames() Method is used to return the names of the members of the current enumeration type. Syntax: public virtual string[] GetEnumNames (); Returns: This method returns an array which contains the names of the members of the enumeration.Exception: This method will give ArgumentException
    2 min read
  • C# | Type.GetTypeHandle() Method
    Type.GetTypeHandle() Method is used to get the handle for the Type of a specified object. Syntax: public static RuntimeTypeHandle GetTypeHandle (object o); Here, it takes the object for which to get the type handle. Return Value: This method returns The handle for the Type of the specified Object. E
    2 min read
  • C# | Type.GetProperties() Method
    Type.GetProperties() Method is used to get the properties of the current Type. There are 2 methods in the overload list of this method as follows: GetProperties() Method GetProperties(BindingFlags) Method GetProperties() Method This method is used to return all the public properties of the current T
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences