如何计算ArrayList中的值 [英] How to count value in a ArrayList

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

问题描述

你好!


我有一个带有许多double的ArrayList,它们中的一些已经被排序了两个

值在ArrayList中存在多一次。 />
是否可以在C#或框架中使用某些功能来计算每个

唯一的双值,或者是唯一的

解决方案。列出并计算每个唯一的双倍值。


// Tony

Hello!

I have an ArrayList with many double that is sorted some of these double
value exist more then once in the ArrayList.
Is it possible to use some feature in C# or from the framework to count each
unique double value or is the only
solution to run through the list and count every unique double value.

//Tony

推荐答案

如果可以使用LINQ,那么这个页面是一个很好的资源
http:/ /msdn.microsoft.com/en-us/vcsharp/aa336747.aspx


查看Aggregate Operators的示例 - Count - Grouped。


" Tony"写道:
If you can use LINQ, then this page is an excelent resource
http://msdn.microsoft.com/en-us/vcsharp/aa336747.aspx.

Look at the example for Aggregate Operators - Count - Grouped.

"Tony" wrote:

您好!


我有一个带有许多双精度的ArrayList,其中包含了其中的一些双重

值在ArrayList中存在多次。

是否可以在C#或框架中使用某些功能来计算每个

唯一的双值或者是唯一的

解决方案贯穿列表并计算每个唯一的双倍值。


// Tony
Hello!

I have an ArrayList with many double that is sorted some of these double
value exist more then once in the ArrayList.
Is it possible to use some feature in C# or from the framework to count each
unique double value or is the only
solution to run through the list and count every unique double value.

//Tony


2008年5月23日星期五13:43:17 +0200,Tony写道:
On Fri, 23 May 2008 13:43:17 +0200, Tony wrote:

您好!


我有一个带有许多double的ArrayList,它们中的一些被分类了两个

值在ArrayList中存在多一次。是否可以在C#或框架中使用一些

功能来计算每个唯一的双值或

是唯一的

解决方案通过列表并计算每个唯一的双倍值。


// Tony
Hello!

I have an ArrayList with many double that is sorted some of these double
value exist more then once in the ArrayList. Is it possible to use some
feature in C# or from the framework to count each unique double value or
is the only
solution to run through the list and count every unique double value.

//Tony



也许尝试使用哈希表而不是数组列表,搜索一个

哈希表是O(1)而不是列表O(n)。


关于j1mb0jay

Maybe try using a hash table rather that an array list, searching of a
hash table is O(1) rather than a list O(n).

Regards j1mb0jay


5月23日下午12:43,Tony < johansson.anders ... @ telia.comwrote:
On May 23, 12:43 pm, "Tony" <johansson.anders...@telia.comwrote:

我有一个带有许多双精度的ArrayList,其中包含了其中的一些双重

值在ArrayList中存在多次。

是否可以在C#中使用某些功能或从框架中计算每个

唯一的双值或者是唯一的

解决方案来运行列表并计算每个唯一的double值。
I have an ArrayList with many double that is sorted some of these double
value exist more then once in the ArrayList.
Is it possible to use some feature in C# or from the framework to count each
unique double value or is the only
solution to run through the list and count every unique double value.



除了其他回复之外,我会注意到直接比较双重
值通常是一件坏事。两个

计算序列是逻辑上的。相同的可以有不同的结果

,有时候出于非常奇怪的原因可以使用JIT

优化等等。通常情况下比较一定比较优惠

容差。这些双打代表什么,它们来自哪里?
来自哪里?不同的情况值得采用不同的方法。


Jon

Leaving aside the other responses, I''d note that comparing double
values against each other directly is usually a bad thing. Two
sequences of calculations which are "logically" identical can have
different results, sometimes for very odd reasons to do with JIT
optimisations etc. It''s usually better to compare within a certain
tolerance. What are these doubles representing, and where have they
come from? Different situations merit different approaches.

Jon


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

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