TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ronwaldo cruz
NA
1
0
C# Generics problem
Jan 20 2010 2:20 AM
Hi,
I have a problem dealing with Generics.
Some background:
The Animal class is a generified class that needs to be associated with a particular person
Dog is an animal that can only be associated with the class Doctor (a subclass of Person)
Cat is an animal that can only be associated with the class Painter (a subclass of Person)
I need a method (named SomeMethod) that will take in new lists of animals
SomeMethod will primarily deal with the Owner property from the Animal class
using System.Collections.Generic;
namespace Test
{
class Program
{
static void Main()
{
SomeMethod(new List<Animal<Person>>(), new List<Dog>());
}
public static void SomeMethod<T>(IList<Animal<T>> a, IList<Animal<T>> b)
where T : Person
{
//do something
}
}
class Animal<T>
where T : Person
{
public T Owner { get; set; }
}
class Dog : Animal<Doctor>
{
}
class Cat : Animal<Painter>
{
}
class Person
{
}
class Doctor : Person
{
}
class Painter : Person
{
}
}
Would anybody have an idea?
Reply
Answers (
0
)
iso creating
Adding events at run time