Mega Code Archive

 
Categories / C# Book / 09 Reflection
 

0624 Get members

When called with no arguments, GetMembers returns all the public members for a type (and its base types). GetMember retrieves a specific member by name: using System; using System.Reflection; using System.Collections.Generic; class MyClass { private bool v; public void MyValue() { v = true; } } class Program { static void Main() { MemberInfo[] m = typeof(MyClass).GetMember("MyValue"); Console.WriteLine(m[0]); // Void MyValue() } } The output: Void MyValue()