Announcement

Collapse
No announcement yet.

How to get class members name + type info

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    How to get class members name + type info

    For this code:
    public class MyClass
    {
        public string   sr = "abc";
        public int[]    br = {777, 888, 555};
        public float    fr = 3.1415f;
    }
    
    public class App
    {
        public static void Main()
        {
            MemberInfo[] ma = typeof(MyClass).GetMembers();
            foreach (MemberInfo m in ma)
            {
                Console.WriteLine(m.Name + ":" + m.GetType());
            }
        }
    }
    I expect output like this:
    • .ctor:System.Object
    • sr:System.String
    • br:System.Array
    • fr:System.Float
    but real output is:
    • .ctor:System.Object
    • sr:System.Object
    • br:System.Object
    • fr:System.Object
    What I'm doing wrong?
    Last edited by DimPal; 2018-09-08 @ 12:13 PM.

    #2
    Oh, sorry. Problem solved.

    Comment

    Working...
    X