C# Reflection - Get field values from a simple class

后端 未结 3 1487
醉话见心
醉话见心 2020-11-27 07:10

I have a class:

class A {
    public string a = \"A-val\" , b = \"B-val\";
}

I want to print the object members by reflection

3条回答
  •  死守一世寂寞
    2020-11-27 07:21

    Remember when you write fields like :

    public string VarName{ get; set;}
    

    Then actually you have this code(this is what reflection see) :

    private string _varName;
    public string get_VarName(){
    ....
    }
    public void set_VarName(strig value){
    ....
    }
    

提交回复
热议问题