![]() |
【转帖】[转]stringcollection faq - 精华帖集合
[转]stringcollection faq - 精华帖集合
www.dimcax.com [转]stringcollection faq q:如何使用stringcollection[1]? a:通常我们有三种方法来访问stringcollection里面的string元素: // code #01 stringcollection sc = new stringcollection(); sc.addrange(textbox1.lines); // stringcollection used together with stringenumerator. stringenumerator se = sc.getenumerator(); while (se.movenext()) { console.writeline(se.current); } // 'foreach' syntax used. foreach(string str in sc) { console.writeline(str); } // 'for' syntax used. for(int i = 0; i < sc.count; i++) { console.writeline(sc); } q:与arraylist相比,stringcollection有什么优势? a:首先让我们来看看如下代码: // code #02 // stringcollection used for strings operation. stringcollection sc = new stringcollection(); sc.addrange(textbox1.lines); foreach (string str in sc) { if (str.trim().startswith("file")) { // do something } else if (str.trim().startswith("registry")) { // do something else } } // arraylist used for strings operation. arraylist al = new arraylist(); al.addrange(textbox1.lines); foreach (object obj in al) { string str = (string)obj; if (str.trim().startswith("file")) { // do something } else if (str.trim().startswith("registry")) { // do something else } } 从上面的代码我们看可以看出,用stringcollection写出的代码更加直观(尤其在你要对集合里面的string元素进行复杂的操作的时候),清楚地表明了集合里面的元素的性质,并且免除我们手动进行强类型转换 装载:systemobjects.dynamiclinker.loadmodule 卸载:systemobjects.dynamiclinker.unloadmodule 已经加载的程序(.arx和.dll):getloadedmodules 看到老大讲了,.net调用arx 和 dll的方法十分的兴奋。自己动手试验了下,发现getloadedmodules 的返回值是stringcollection型,因为以前没有用过从网上找了篇文章转了过来。 书山有路勤为径,学海无涯苦作舟! |
所有的时间均为北京时间。 现在的时间是 05:17 AM. |