using System; using System.Reflection; class MyClass { private int _field1; private string _field2; public void MyMethod() { ... } } class Program { static void Main(string[] args) { Type myType = typeof(MyClass); BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance; MemberInfo[] members = myType.GetMembers(flags); foreach (MemberInfo member in members) { Console.WriteLine(member.Name); } } }
using System; using System.Reflection; class MyClass { public int Property1 { get; set; } public string Property2 { get; set; } public bool Property3 { get; set; } } class Program { static void Main(string[] args) { Type myType = typeof(MyClass); BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; MemberInfo[] members = myType.GetMembers(flags); foreach (MemberInfo member in members) { Console.WriteLine(member.Name); } } }In this example, we are using the GetMembers() method to retrieve all the public properties of the MyClass using BindingFlags.Public. The output of this program will be `Property1`, `Property2`, and `Property3`. These examples require the use of the System.Reflection package library.