On Oct 31, 10:31*am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
> On Thu, 30 Oct 2008 15:49:37 -0700, <yoota...@gmail.com> wrote:
> > I have an Object which has a list of list of objects.
> > For instance,
>
> > public class myClass
> > {
> > * * *public List<FirstClass> myFirstClass {get;set;}
> > * * *public List<SecondClass> mySecondClass {get;set;}
> > }
>
> > And both FirstClass and SecondClass have Id and Title properties.
>
> Do they both inherit/implement a common class or interface with those *
> properties?
>
> If not, you'll have to wait for the release of C# 4.0, which includes a *
> new "dynamic" type allowing for late-binding of class members.
>
> If they do inherit/implement a common class or interface, then you can do*
> what you want with generics as they are now (by the way, note that it's *
> "generic" not "genetic"). *Specifically, let's assume that they both *
> implement an interface that looks like this:
>
> * * *interface ICommon
> * * *{
> * * * * *int Id { get; set; }
> * * * * *string Title { get; set; }
> * * *}
>
> And the class declarations look something like this:
>
> * * *class FirstClass : ICommon { ... }
> * * *class SecondClass : ICommon { ... }
>
> Then, you can write the desired method like this:
>
> * * *void myFunction<T>(List<T> variable) where T : ICommon
> * * *{
> * * *}
>
> A method like that can take as an argument any List<T> where the T *
> implements ICommon. *So a List<FirstClass> or a List<SecondClass> wouldbe *
> valid.
>
> Pete
Thank you very much for your help!!!
|