using System; using System.Reflection; public class MyClass { public int MyProperty { get; set; } } class Program { static void Main(string[] args) { PropertyInfo propertyInfo = typeof(MyClass).GetProperty("MyProperty"); Type propertyType = propertyInfo.GetMemberType(); Console.WriteLine("Type of the property: " + propertyType); } }
using System; using System.Reflection; public class MyClass { public int MyMethod(string parameter) { return 0; } } class Program { static void Main(string[] args) { MethodInfo methodInfo = typeof(MyClass).GetMethod("MyMethod"); ParameterInfo parameterInfo = methodInfo.GetParameters()[0]; Type parameterType = parameterInfo.GetMemberType(); Console.WriteLine("Type of the parameter: " + parameterType); } }In this example, we use the GetMethod method to get a MethodInfo object that represents the MyMethod method of the MyClass class. We then use the GetParameters method to get an array of ParameterInfo objects that represent the parameters of the method. Finally, we call the GetMemberType method on the first element of the array to get the type of the first parameter. Package library: This code uses the System.Reflection namespace which is part of the .NET Framework.