Solved

DescendingComparer problem in SortedList

Posted on 2009-07-09
2
350 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
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

816 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now