By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,453 Members | 1,562 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,453 IT Pros & Developers. It's quick & easy.

Re: Can I cast a generic list, or do I need another approach

P: n/a
On Jun 26, 2:11*pm, "RichB" <ri...@community.nospamwrote:
I have an abstract class Domain which is responsible for validation of my
model. All classes in the model inherit from Domain for operations such as
bool IsValid {get;}.
<snip>
However List<Addressand List<PhoneNumberdoes not cast to List<Domain>..
Is there a way to do this, or are there any other options other than
repeating the code?
Yes, there's a way to do it - you need to make the method generic:

public bool IsChildListValid<T>(List<TdomainList) where T : Domain
{
...
}

That should work with no problems.

Jon
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a

Thanks, just what I was after.

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:71**********************************@56g2000h sm.googlegroups.com...
On Jun 26, 2:11 pm, "RichB" <ri...@community.nospamwrote:
I have an abstract class Domain which is responsible for validation of my
model. All classes in the model inherit from Domain for operations such as
bool IsValid {get;}.
<snip>
However List<Addressand List<PhoneNumberdoes not cast to List<Domain>.
Is there a way to do this, or are there any other options other than
repeating the code?
Yes, there's a way to do it - you need to make the method generic:

public bool IsChildListValid<T>(List<TdomainList) where T : Domain
{
...
}

That should work with no problems.

Jon

Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.