Click here to Skip to main content
16,017,788 members
Home / Discussions / C#
   

C#

 
AnswerRe: Deactivating a form... Pin
Shy Agam25-Jul-07 2:11
Shy Agam25-Jul-07 2:11 
GeneralRe: Deactivating a form... Pin
Paul Conrad25-Jul-07 6:12
professionalPaul Conrad25-Jul-07 6:12 
QuestionAbout TreeView Questions! Pin
snowlover24-Jul-07 15:48
snowlover24-Jul-07 15:48 
Questionis there any way to check the DataTable has been populated? Pin
Khoramdin24-Jul-07 13:00
Khoramdin24-Jul-07 13:00 
AnswerRe: is there any way to check the DataTable has been populated? Pin
Justin Perez24-Jul-07 13:11
Justin Perez24-Jul-07 13:11 
GeneralRe: is there any way to check the DataTable has been populated? Pin
help as an alias24-Jul-07 17:45
help as an alias24-Jul-07 17:45 
QuestionAppending RTF files Pin
bart6024-Jul-07 12:34
bart6024-Jul-07 12:34 
Questiongeneric functions Pin
dfn24-Jul-07 12:21
dfn24-Jul-07 12:21 
I would like to know how to implement generic functions.

I have a few classes: CdRecord, BookRecord, Record, and RecordManager.
CdRecord inherits from Record. BookRecord inherits from Record.

In my RecordManager class, I have a bunch of functions.
Two of the functions in RecordManager read info from a table in an SQL DB.
rough code:

using...

namespace MyProject
{
class RecordManager
{
List<cdrecord> CDrecords = new List<cdrecord>();
List<bookrecord> BOOKrecords = new List<bookrecord>();

public void readBooks()
{
// connect to DB
// fill BOOKrecords with entries from table
}

public void readCds()
{
// connect to DB
// fill CDrecords with entries from table
}
}
}

Now, once I've filled CDrecords and BOOKrecords, I need a function that will split them, and re-arrange the order of the records. I realise I can make one function that takes a List<bookrecord> parameter and one function that takes a List<cdrecord> parameter, but I'd prefer to have one function be able to handle them both. I also know that I can just send an extra parameter (int i for example) that indicates what type i am working with (if i == 1, BookRecord list, etc). However, I don't like this method either. In the future, I may end up with many more classes that inherit from Record, that I'll have lists of that need to be split, and I don't want to have a function for each type because I may end up with 20 redundant functions. Similarly, I don't want to send an extra parameter because of readability (if i == 1, if i == 2, .... if i == 20). How do I make one function that is able to take a paramater of type List<t> where T can be CdRecord or BookRecord?

I have tried the following, and it does not work:

public void SplitRecords<t>(List<t> records, int start, int end)
{
//some code
for(int i = start; i <= end; i++)
{
//some code
records[i].memberFunction();
//some code
}
}

The reason it doesn't work is because "memberFunction()" is a function of Record (which is inherited by BookRecord and CdRecord) but "T" does not have a definition for "memberFunction()"
How do I correct this? Could I be experiencing problems because I am trying to use classes I wrote with generics, rather than int/short/etc.?

Thanks in advance for any assistance!
AnswerRe: generic functions Pin
Christian Graus24-Jul-07 12:35
protectorChristian Graus24-Jul-07 12:35 
QuestionOnHelpButtonClicked Pin
RussBus24-Jul-07 12:10
RussBus24-Jul-07 12:10 
AnswerRe: OnHelpButtonClicked Pin
Martin#24-Jul-07 19:53
Martin#24-Jul-07 19:53 
GeneralRe: OnHelpButtonClicked Pin
RussBus25-Jul-07 5:30
RussBus25-Jul-07 5:30 
GeneralRe: OnHelpButtonClicked Pin
RussBus25-Jul-07 5:58
RussBus25-Jul-07 5:58 
GeneralRe: OnHelpButtonClicked Pin
Martin#25-Jul-07 19:37
Martin#25-Jul-07 19:37 
QuestionDynamic XML Search Pin
cp16net24-Jul-07 11:44
cp16net24-Jul-07 11:44 
AnswerRe: Dynamic XML Search Pin
il_masacratore25-Jul-07 11:17
il_masacratore25-Jul-07 11:17 
QuestionEncryption Pin
Richard Andrew x6424-Jul-07 11:22
professionalRichard Andrew x6424-Jul-07 11:22 
AnswerRe: Encryption Pin
Christian Graus24-Jul-07 11:23
protectorChristian Graus24-Jul-07 11:23 
GeneralRe: Encryption Pin
Richard Andrew x6424-Jul-07 11:45
professionalRichard Andrew x6424-Jul-07 11:45 
GeneralRe: Encryption Pin
Christian Graus24-Jul-07 12:05
protectorChristian Graus24-Jul-07 12:05 
GeneralRe: Encryption Pin
ekynox24-Jul-07 14:28
ekynox24-Jul-07 14:28 
GeneralRe: Encryption Pin
Richard Andrew x6424-Jul-07 14:32
professionalRichard Andrew x6424-Jul-07 14:32 
Questionresend mouse messages Pin
likefood24-Jul-07 11:07
likefood24-Jul-07 11:07 
AnswerRe: resend mouse messages Pin
Dave Kreskowiak24-Jul-07 13:05
mveDave Kreskowiak24-Jul-07 13:05 
GeneralRe: resend mouse messages Pin
likefood25-Jul-07 3:19
likefood25-Jul-07 3:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.