Solved

DescendingComparer problem in SortedList

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

937 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

6 Experts available now in Live!

Get 1:1 Help Now