通过字符串或字符索引数组 [英] indexing array through string or character

查看:68
本文介绍了通过字符串或字符索引数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在生成类似文本框的控件,动态地为不同的主题添加标签,这些控件进一步取决于所选的标准,现在我必须交叉检查是否生成了这些控件,例如,如果我选择标准9,则主题的控件将是数学,科学等,如果我选择了11科学,那将是物理学,化学等.因为我采用了bool [] b数组,其中我指定b [0]用于数学,如果生成了数学文本框,则将其设置为true,否则是错误的.

现在我需要的是我可以像b ["Maths]] = true或b [" M] = true这样的数组吗?即是否可以使用字符串或字符??遍历或迭代到数组??

请让我知道是否可能...

谢谢&问候,
Krunal Panchal

Hello everyone,

I am generating controls like textbox ,labels dynamically for different subjects which are further dependent on the standard selected now i have to cross check that which controls are generated like if i select standard 9 then controls of subjects would be of Maths, science etc and if i select 11th science then it would be physics , chemistry etc. for that i have taken an bool[] b array in which i specify that b[0] is for Maths and if maths textbox is generated then it is set to true else it is false.

Now what i need is can i have array like this b["Maths"]=true OR b["M"]=true?? i.e. is it possible to traverse or iterate to an array using string or character ??

Please let me know if it is possible ...

Thanks & Regards,
Krunal Panchal

推荐答案

此类索引功能是通过以下通用类之一实现的:
Such indexing functionality is achieved through one of the following generic classes:
  • System.Collections.Generic.Dictionary<TKey, TValue>;
    http://msdn.microsoft.com/en-us/library/xfhwa508.aspx[^];
  • System.Collections.Generic.SortedDictionary<TKey, TValue>;
    http://msdn.microsoft.com/en-us/library/f7fta44c.aspx[^];
  • System.Collections.Generic.SortedList<TKey, TValue>;
    http://msdn.microsoft.com/en-us/library/ms132319.aspx[^].


这篇关于通过字符串或字符索引数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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