-
March 26th, 2010, 08:15 PM
#1
[RESOLVED] Generics question
I have a question about generics. I was wondering if there was a way to rewrite this:
class ByFirstNameComparer : IComparer<Person>
{
public int Compare(<Person> p1, <Person> p2)
{...}
}
To something like this:
class ByFirstNameComparer : IComparer<T> where T is Person
{
public int Compare(<T> p1, <T> p2)
{...}
}
.net 4.0? VS2010 Ultimate V10.0.30128.1 RC1Rel
Thanks,
Matthew
-
March 26th, 2010, 08:17 PM
#2
Re: Generics question
err (Person p1, Person p2)
-
March 27th, 2010, 05:02 PM
#3
Re: Generics question
Originally Posted by MattInSD73
err (Person p1, Person p2)
Code:
public class ByFirstNameComparer<T> : IComparer<T> where T : Person
{
public int Compare(T p1, T p2){
return //..... your code here
}
}
public class Person { }
This should work
Last edited by JonnyPoet; March 27th, 2010 at 05:07 PM.
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
March 28th, 2010, 01:09 PM
#4
Re: Generics question
Thanks! I thought there was a was to make it more "loosely coupled" than I had it written originally(if that's the correct term).
~M
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|