Getting all Properties of Class using Reflection C#

Helps to Get all the Properties from the Class

public void GetPropertiesUsingReflection()
        {
            PropertyInfo[] propertyInfos = typeof(Student).GetProperties();

            // writes all the property names
            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                Response.Write(propertyInfo.Name + "<br/>");
            }
        }

Output:

Name
Grade

Used Class for Demo:

class Student
    {
        private string _name;
        private double _grade;

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }


        public double Grade
        {
            get { return _grade; }
            set { _grade = value; }
        }

        public void M1()
        {
            //Code
        }

        public void M2()
        {
            //Code
        }

        public string M3()
        {
            return string.Empty;
        }

        public Student(string name, double grade)
        {
            this.Name = name;
            this.Grade = grade;
        }
    }

Thanks for reading this article. Have a nice day.

Next Recommended Reading Getting Alphabets from Number using C#