473,406 Members | 2,293 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,406 software developers and data experts.

Problem with delegates while sorting

Hi guy
In System.Collections.Generic.SortedDictionary one of the constructors takes
an IComparer<Tas its argument.I'd like to sort my dictionary by its key.Im
using
class CComparer : IComparer<person>

{

public int Compare(person p1, person p2)

{

return p1.age.CompareTo(p2.age);

}

}

then

SortedDictionary<person , charlist = new SortedDictionary<person ,
char>(new CComparer());

It works fine but i'd like to use delegates instead. Unfortunately compiler
gives me an error 'cannot convert from 'anonymous method' to
'System.Collections.Generic.IDictionary'' My delegate is mistakenly taken
for IDictionary,which is an argument in another constructor ;/, any ideas?

SortedDictionary<person, charlist = new SortedDictionary<person,
char>(delegate (person p1,person p2)

{ return p1.age.CompareTo(p2.age); });

Best regards!
Jun 17 '07 #1
1 1365
kriz <kr**@vp.plwrote:

<snip>
It works fine but i'd like to use delegates instead. Unfortunately compiler
gives me an error 'cannot convert from 'anonymous method' to
'System.Collections.Generic.IDictionary'' My delegate is mistakenly taken
for IDictionary,which is an argument in another constructor ;/, any ideas?
There aren't any constructors to SortedDictionary which take a
Comparison<T- that's the problem.

If it's any help, I've got a ComparisonConverter class in my MiscUtil
library which implements IComparer<Thaving been passed a Comparison
<Tin the constructor.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 17 '07 #2

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

Similar topics

4
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand AsyncCallback methods. But I need some clarification on...
2
by: OpticTygre | last post by:
Ok, so I've been trying and trying to learn about delegates, but I still can't grasp the concept of the advantages. Why use delegate functions instead of calling the function directly? In other...
8
by: Dominique | last post by:
In order to become more familiar with the Model-View-Controller pattern, I have written a demo where each View is a plugin and the plugins are loaded at startup from the plugins directory. When the...
6
by: per9000 | last post by:
An interesting/annoying problem. I created a small example to provoke an exception I keep getting. Basically I have a C-struct (Container) with a function-pointer in it. I perform repeated calls...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
3
by: james | last post by:
Hi guys, I create a delegate and pass in a local variable. When the variable is a reference type everything works fine, but when it is a valuetype the delegate uses the value of the last...
1
by: Ahmed Yasser | last post by:
Hi all, i have a problem with the datagridview sorting, the problem is a bit complicated so i hope i can describe in the following steps: 1. i have a datagridview with two columns...
69
by: raylopez99 | last post by:
They usually don't teach you in most textbooks I've seen that delegates can be used to call class methods from classes that are 'unaware' of the delegate, so long as the class has the same...
9
by: raylopez99 | last post by:
Hello all— I’m trying to get the below to work and cannot get the format right. It’s from this example: http://msdn.microsoft.com/en-us/library/8627sbea(VS.71).aspx What it is: I’m trying...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.