Solved

DescendingComparer problem in SortedList

Posted on 2009-07-09
2
354 Views
Last Modified: 2012-05-07
The following code is from .NET Framework 2.0 p220
it results in the following 3 errors
1      The type or namespace name 'DescendingComparer' could not be found (are you missing a using directive or an assembly reference?)      C:\Documents and Settings\xxxx\My Documents\Visual Studio 2005\Projects\SortedListDescending220\SortedListDescending220\Program.cs      
2      The best overloaded method match for 'System.Collections.SortedList.SortedList(int)' has some invalid arguments      C:\Documents and Settings\xxxx\My Documents\Visual Studio 2005\Projects\SortedListDescending220\SortedListDescending220\Program.cs
3      Argument '1': cannot convert from 'DescendingComparer' to 'int'      C:\Documents and Settings\xxxx\My Documents\Visual Studio 2005\Projects\SortedListDescending220\SortedListDescending220\Program.cs

using System;
using System.Collections;
using System.Text;
 
namespace SortedListDescending220
{
    class Program
    {
        static void Main(string[] args)
        {
            SortedList sort = new SortedList(new DescendingComparer());
            sort["First"] = "1st";
            sort["Second"] = "2nd";
            sort["Third"] = "3rd";
            sort["Fourth"] = "4th";
            foreach (DictionaryEntry entry in sort)
            {
                Console.WriteLine("{0} = {1}", entry.Key, entry.Value);
            }
 
        }
    }
}

Open in new window

0
Comment
Question by:AstroGuy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 500 total points
ID: 24816291
You have to define the DescendingComparer class also, there is no such class in the framework.

As you are using framework 2, you should really consider using the strongly typed class SortedList<TKey, TValue> instead.
0
 

Author Closing Comment

by:AstroGuy
ID: 31601737
You were absolutely correct, the Class was deined earlier in the book.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question