C# Dynamic如何动态添加属性

C# Dynamic如何动态添加属性,第1张

1)定义一个委托,参数个数可变,参数都是object类型:这里的委托多有个dynamic参数,代表调用这个委托的动态对象本身.

2)定义一个委托转载对象,因为dynamic对象不能直接用匿名方法,这里用对象去承载:

3) 定义一个动态对象:

你用数据链表来做,也可以用C++ STL来做,看你那个顺手。

可以程序启动的时候,读到配置文件中的字符串,然后根据分割符号生成一个数组,或者直接添加到map中

以下是STL中的map,请参考相关知识点

#include "stdafx.h"

#include <iostream>

#include <map>

#include <string>

using namespace std

int _tmain(int argc, _TCHAR* argv[])

{

typedef map<string ,string>DICT

DICT dict

dict.insert(DICT::value_type("name","张某某"))

dict.insert(DICT::value_type("units","设备厂"))

dict.insert(DICT::value_type("job"," *** 作员"))

DICT::iterator iter

for(iter = dict.begin()iter !=dict.end()iter ++)

{

cout<<(*iter).first<<":"<<(*iter).second<<endl

}

getchar()

return 0

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11451072.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-16
下一篇2023-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存