Solved

DescendingComparer problem in SortedList

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

15 Experts available now in Live!

Get 1:1 Help Now