python 实体类_C#、Python中分别是怎么实现通过字符串获取实体类的值以及给实体类赋值...

namespace ConsoleApplication1

{class Program

{static void Main(string[] args)

{#region 通过字符串设置实体类的值

//初始化一个实体类//Student model_stu = new Student();

//string id_str = "stu_id";

//string name_str = "stu_name";

//string addr_str = "stu_address";

//Type type = model_stu.GetType();//获取类型

//PropertyInfo property_info_id = type.GetProperty(id_str);

//PropertyInfo property_info_name = type.GetProperty(name_str);

//PropertyInfo property_info_addr = type.GetProperty(addr_str);

通过字符串获取实体类的值

Student model_stu =

{

stu_id

= = =

};

id_str = name_str = addr_str =

Type type

= model_stu.GetType();

PropertyInfo property_info_id =

PropertyInfo property_info_name

=

PropertyInfo property_info_addr

=

Console.WriteLine(property_info_id.GetValue(model_stu));

Console.WriteLine(property_info_name.GetValue(model_stu));

Console.WriteLine(property_info_addr.GetValue(model_stu));

Console.ReadKey();

}

}

{

stu_id { ; stu_name { ; stu_address { ;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值