任何人都可以建议如何做到最好。任何建议或帮助都是非常感谢! 谢谢, Calvert 对于数据类型,一般的经验法则是,如果你计划使用它来进行一些计算(如加法,减法等),那么/> 那么它应该是某种数字类型(int,double,decimal)。 如果你只是要存储它,那么使用一个字符串。例如, 即使电话号码都是数字,你应该使用一个字符串 ,因为你不用电话号码进行计算。 对于你的问题,我认为你最好的选择是使用通用的 字典。使用ID作为键,值作为计数。阅读 数组中的每个值,检查它是否已存在于 字典中。如果是,那么只需增加计数,否则,将 添加到字典中。 Dim values()As Integer = {1,4, 6,23,6,2,54,1,6,23,2,4,1,6} Dim idCount As New Dictionary(Of String,Integer)() For Each i As Integer In values''Check 数组中的每个值 如果idCount.ContainsKey(i.ToString())那么''如果字典中已经存在值 idCount(i.ToString)+ = 1 ''递增计数价值 否则 ''否则 idCount.Add(i.ToString(),1)''add 字典值 结束如果 下一页 希望这会有所帮助 Chris 非常感谢你们。这正是我想要的信息。正在寻找。我现在要试一试。再次感谢。 I need to some sort of data type that will hold a listing of ID''s andtheir counts/frequency. As I do some processing I get an ID backwhich I need to store and keep an accurate count for how many timesthat ID is listed. For example I might get a listing of thesenumbers:1,4,6,23,6,2,54,1,6,23,2,4,1,6I will get those numbers one at a time and need to build somethinglike1,34,26,423,22,243,1In above number X,Y:X- is the numberY- is the count of the numberI then need to sort the data on the Y (the count) column:6,41,34,223,22,243,1Can anyone suggest how best to do this. Any suggestions or help ismuch appreciated!Thanks,Calvert 解决方案 I would store this in a Dictionary<int, intwhere the key is the id andthe value is the count.Then, when you need to sort the keys, I would enumerate through theKeyValuePair instances and sort those (Dictionary<TKey, TValueimplementsIEnumerable<KeyValuePair<TKey, TValue>>). You can simply put them into anarray and then call the static Sort method on the Array class, passing in ananonymous method for the Comparison<Tdelegate (which in this case, wouldbe Comparison<KeyValuePair<int, int>>) which would compare the values basedon the count.You could also get away with using a DataTable with an id column and acount column, and then just placing a data view on the data table which issorted by the count.--- Nicholas Paldino [.NET/C# MVP]- mv*@spam.guard.caspershouse.com<ca**********@gmail.comwrote in messagenews:89**********************************@d61g2000 hsa.googlegroups.com...>I need to some sort of data type that will hold a listing of ID''s andtheir counts/frequency. As I do some processing I get an ID backwhich I need to store and keep an accurate count for how many timesthat ID is listed. For example I might get a listing of thesenumbers:1,4,6,23,6,2,54,1,6,23,2,4,1,6I will get those numbers one at a time and need to build somethinglike1,34,26,423,22,243,1In above number X,Y:X- is the numberY- is the count of the numberI then need to sort the data on the Y (the count) column:6,41,34,223,22,243,1Can anyone suggest how best to do this. Any suggestions or help ismuch appreciated!Thanks,Calvert On Nov 19, 9:53 am, [email protected] wrote:I need to some sort of data type that will hold a listing of ID''s andtheir counts/frequency. As I do some processing I get an ID backwhich I need to store and keep an accurate count for how many timesthat ID is listed. For example I might get a listing of thesenumbers:1,4,6,23,6,2,54,1,6,23,2,4,1,6I will get those numbers one at a time and need to build somethinglike1,34,26,423,22,243,1In above number X,Y:X- is the numberY- is the count of the numberI then need to sort the data on the Y (the count) column:6,41,34,223,22,243,1Can anyone suggest how best to do this. Any suggestions or help ismuch appreciated!Thanks,CalvertAs for data types, a general rule of thumb would be that if you planto do some calculations with it (like addition, subtraction, etc.)then it should be some sort of numeric type (int, double, decimal).If you are only going to store it, then use a string. For example,even though a phone number is all digits, you should use a stringsince you don''t do calculations with a phone number.For you problem, I think your best bet would be to use a genericdictionary. Use the ID as the key and the value as the count. Readeach value in the array, check to see if it already exists in thedictionary. If it does, then just increment the count, otherwise, addit to the dictionary.Dim values() As Integer = {1,4,6,23,6,2,54,1,6,23,2,4,1,6}Dim idCount As New Dictionary(Of String, Integer)()For Each i As Integer In values ''Checkeach value in the arrayIf idCount.ContainsKey(i.ToString()) Then ''If the valuealready exists in the dictionaryidCount(i.ToString) += 1''increment the count for that valueElse''otherwiseidCount.Add(i.ToString(), 1) ''addthe value to the dictionaryEnd IfNextHope this helpsChrisThank you both very much. That was exactly the information I waslooking for. I am going to give it a shot now. Thanks again. 这篇关于什么是最好的数据类型..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-23 23:08