473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

performancecounters and IComparable/IComparer

Hi, I am creating an array of performancecounter objects and wondering if it
is possible to sort this array according to category Names.
I tried Array.Sort(AllCountersCategories) but it is erroring. I understood
that to be able to sort an array its contents should implement the
IComparable/IComparer interface.
So the question is how can we know if an object implements this interface or
not, the 2nd of course, any idea of how to sort this array containing
performance counters object according to category names?

Thanks
Jun 27 '08 #1
1 1258
Thanks Jeroen and Cor for your replies!

Hi Salam,
>I understood from documentation that hashtable can not be sorted?
Yes, you're right. A hashtable could not be sorted. To get a "sorted
hashtable", you can use System.Collections.SortedList or
System.Collections.Generic.SortedList<TKey,TValuea s Cor has suggested.

The following comments are quoted from MSDN document:

"A SortedList element can be accessed by its key, like an element in any
IDictionary implementation, or by its index, like an element in any IList
implementation. A SortedList object internally maintains two arrays to
store the elements of the list; that is, one array for the keys and another
array for the associated values."

"The elements of a SortedList object are sorted by the keys either
according to a specific IComparer implementation specified when the
SortedList is created or according to the IComparable implementation
provided by the keys themselves. In either case, a SortedList does not
allow duplicate keys."

For more information on the SortedList and SortedList<TKey,TValueclasses,
please refer to the following MSDN documents:

http://msdn.microsoft.com/en-us/libr...rtedlist(VS.85)
.aspx
http://msdn.microsoft.com/en-us/libr...19(vs.80).aspx

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Cybertof | last post by:
Hello, Could someone please explain me the difference between the 2 interfaces IComparable and IComparer ? In which cases use one or the other ? Are they dedicated to own classes or built-in...
1
by: Fernando Rodríguez | last post by:
Hi, I don't understand very well the diferences between both. When should each be used? Thanks
2
by: ESPNSTI | last post by:
Hi, I'm trying to use a generics dictionary with a key class that implements and needs IComparable<>. However when I attempt to use the dictionary, it doesn't appear to use the IComparable<> to...
1
by: Brett Romero | last post by:
What are the reasons to use one over the other? SortedList implements IComparer.Compare(). Why would you also want to create a SortedList class that implements IComparable.CompareTo()? I know...
1
by: Steph | last post by:
Hello, i dot not manage to write the code to sort a array on multiple columns. ArrayList people = new ArrayList(); people.Add(new Person("John", "Doe", 76)); people.Add(new Person("Matt", "Dire",...
8
by: SimeonArgus | last post by:
I need to sort a list of points, so I've considered using an IComparable implementation. Should be easy, right? But I need to know two things in the CompareTo function, not one. Test1: I need to...
1
by: Stephen.Schoenberger | last post by:
Hello, I am trying to figure out how to make an IComparable Byte Array Comparison class in C# and keep running into dead ends. I have read where this isn't possible and have seen a few hints...
10
by: Tony | last post by:
Hello! I'm reading in a book and this can't be correct it says. "Objects passed to Comparer.Compare() are checked to see if they support IComparable. If they do, then that implementation is...
1
by: Mitch | last post by:
I have several classes that inherit other classes. I need to be able to sort the Mesh class based on its inherited list of Poly.ZMax,. How do I use IComparer or IComparable to achieve this? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.