将字符串调用为Function [英] call string as Function

查看:77
本文介绍了将字符串调用为Function的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要州和城市的硬编码..



i我有50个函数,因为我有50个状态,我从中调用了一个关于combobox1_selectedindexchanged的函数事件。



因为我创造了一个包含50个案例的开关案例。其中combobox1的选定索引作为案例编号传递。

现在要添加10个函数,我认为开关案例不方便,



所以我有一个想法,是否可能?



i want to hard code for states and cities..

i am having 50 functions as i am having 50 states, from which i am calling a function on combobox1_selectedindexchanged event.
.
for that i have create a switch case with 50 cases. where combobox1's selected index is passed as a case no.
now 10 functions are to be added, i think switch case is not being convenient for that,
.
so i have a idea, is it possible?

functionName+combobox.selectedindex+();





这样我的60个案例将减少到只有一个功能?



或者还有其他选择..





so that my 60 cases will reduced to only one function ??
.
or there is any other option..

.

推荐答案

你可以使用一组代表,例如,见:功能指针数组? [ ^ ]。
You might use an array of delegates, see for instance, here: "Array of Function Pointers?"[^].


这篇关于将字符串调用为Function的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆