如何使用stringlist。 [英] how to use stringlist.

查看:80
本文介绍了如何使用stringlist。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我们的应用程序使用C#窗体。在我的应用程序中,我使用了stringlist来存储项目。在列表中添加项目没有问题。但每当我从列表中删除元素时,都会产生问题。例如



I am using C# windows form for our application. In my application i have used stringlist to store items. there is no problem to add item in list. but whenever i delete element form the list, it will create problems. for e.g.

0 a
1 b
2 c
3 d



如果我从列表中删除项目'b'。列表变为:




if i delete item 'b' from the list. the list becomes:

0 a
1 c
2 d





所有项目的索引已更改。我需要表没有任何索引更改但它填充null或删除索引中的一些符号:





index of all items changed. i need table without any change in index but it fill null or some symbol from the deleted index:

0 a
1 null/0/any symbol
2 c
3 d





使用任何其他方法的任何进一步建议。



谢谢



any further advice to use any other method.

Thanks

推荐答案

问题完全错了。而不是询问使用 StringList ,这是已经把你置于错误位置的决定,你应该问我应该使用什么数据结构?当然,这取决于你的目标。如果你需要处理一些索引之间的固定关系,比如一些字符串,你需要使用一种基于键值对的类型,例如:

https://msdn.microsoft.com/en-us/library/xfhwa508(v=vs。 110).aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/f7fta44c(v = vs.110).aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/ms132319(v=vs.110).aspx [ ^ ]。



-SA
The question is simply wrong. Instead of asking about the use of StringList, which is decision which already puts you in a wrong position, you should have asked "what data structure I should use?" Certainly, it depends on your goal. If you need to work with fixed relationship between some indices and, say, some strings, you would need to use one of the types based on key-value pairs, such as:
https://msdn.microsoft.com/en-us/library/xfhwa508(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/f7fta44c(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/ms132319(v=vs.110).aspx[^].

—SA


尝试:

Try:
myStringList[1] = null;


这篇关于如何使用stringlist。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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