PC Review


Reply
Thread Tools Rate Thread

C# using Genetics

 
 
yootaeho@gmail.com
Guest
Posts: n/a
 
      30th Oct 2008
Hi,

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.

Now I would like to create a function that takes a genetic list type
and then inside the function I would like to access Id and Title value

So something like this

public void myFunction (genetic variable)
{
// here I would like to access variable's Id and Title
}


myFunction(myClass.myFirstClass);
myFunction(myClass.mySecondClass);

Would you be able to help me to write the function me?

Thanks in advance,

Taeho
 
Reply With Quote
 
 
 
 
yootaeho@gmail.com
Guest
Posts: n/a
 
      31st Oct 2008
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!!!
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using C# genetics yootaeho@gmail.com Microsoft C# .NET 0 30th Oct 2008 10:43 PM
get new medical or genetics power point templets =?Utf-8?B?TWVkIFN0dWRlbnQ=?= Microsoft Powerpoint 2 10th Dec 2005 04:51 AM
Genetics with Excel: Determining ratios from Punnett Square Crosses Brett Microsoft Excel Worksheet Functions 2 4th Dec 2005 07:33 AM
MS Puzzle Collection - Mixed Genetics Crashes Stystem Dave Lamar Windows XP Games 1 16th Feb 2004 12:45 AM
MS Puzzle Collection - Mixed Genetics =?Utf-8?B?RExhbWFy?= Windows XP Games 1 15th Feb 2004 06:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:34 PM.