Click here to Skip to main content
15,888,521 members
Home / Discussions / C#
   

C#

 
AnswerRe: datagrid view to pdf by iTextsharp Pin
Gerry Schmitz1-Jun-17 16:46
mveGerry Schmitz1-Jun-17 16:46 
QuestionHow can i effectively write the code for calling a function before and after execution of every function in a class. Pin
yeswanthkumar30-May-17 2:51
yeswanthkumar30-May-17 2:51 
AnswerRe: How can i effectively write the code for calling a function before and after execution of every function in a class. Pin
Pete O'Hanlon30-May-17 3:11
mvePete O'Hanlon30-May-17 3:11 
AnswerRe: How can i effectively write the code for calling a function before and after execution of every function in a class. Pin
Gerry Schmitz30-May-17 12:41
mveGerry Schmitz30-May-17 12:41 
AnswerRe: How can i effectively write the code for calling a function before and after execution of every function in a class. Pin
BillWoodruff1-Jun-17 6:06
professionalBillWoodruff1-Jun-17 6:06 
GeneralRe: How can i effectively write the code for calling a function before and after execution of every function in a class. Pin
yeswanthkumar1-Jun-17 20:31
yeswanthkumar1-Jun-17 20:31 
GeneralRe: How can i effectively write the code for calling a function before and after execution of every function in a class. Pin
BillWoodruff2-Jun-17 6:07
professionalBillWoodruff2-Jun-17 6:07 
QuestionUsing A Generic Class with a Type Constraint Pin
Richard Andrew x6429-May-17 9:24
professionalRichard Andrew x6429-May-17 9:24 
OK, here's a real mind-twister. I can't figure out how to declare the parameter of a function as deriving from a generic class.

Here's the code:
C#
public class BusinessObjectBase
{
}

public class BusinessObjectList<T> : List<T> where T : BusinessObjectBase
{}

public class BusinessObjectDataSet : DataSet
{
    protected BusinessObjectList<BusinessObjectBase>[] _BusinessObjectListArray = null;

    public virtual void AddBusinessObjectList(BusinessObjectList<BusinessObjectBase> List)
    {

    }


}

I want to specify the variable as type BusinessObjectList<T> where T derives from BusinessObjectBase.

The code above compiles fine, but when I go to use the classes, that's the problem:
C#
private class MyBusinessObject : BusinessObjectBase
{
    public MyBusinessObject()
    {

    }
}

private class MyBusinessObjectList<MyBusinessObject> : BusinessObjectList<T> where T : BusinessObjectBase
{

}


 BusinessObjectDataSet Set = new BusinessObjectDataSet();

 MyBusinessObject Bo = new MyBusinessObject();                                                 // Derives from BusinessObjectBase

 MyBusinessObjectList<MyBusinessObject> BoList = new MyBusinessObjectList<MyBusinessObject>(); // Derives from BusinessObjectList<T>

 Set.AddBusinessObjectList(BoList);  // Here it says "Error CS1503  Argument 1: cannot convert from 'MyBusinessObjectList<MyBusinessObject>' to 'BusinessObjectList<BusinessObjectBase>'

What am I doing wrong?

Thank you for taking the time to grok this.

EDIT: Fixed an omission in the code. Revised the question that I'm asking.



The difficult we do right away...
...the impossible takes slightly longer.


modified 29-May-17 16:14pm.

AnswerRe: Using A Generic Class with a Type Constraint Pin
OriginalGriff29-May-17 22:24
mveOriginalGriff29-May-17 22:24 
GeneralRe: Using A Generic Class with a Type Constraint Pin
Richard Andrew x6430-May-17 1:13
professionalRichard Andrew x6430-May-17 1:13 
AnswerRe: Using A Generic Class with a Type Constraint Pin
Pete O'Hanlon29-May-17 23:48
mvePete O'Hanlon29-May-17 23:48 
GeneralRe: Using A Generic Class with a Type Constraint Pin
Richard Andrew x6430-May-17 1:14
professionalRichard Andrew x6430-May-17 1:14 
AnswerRe: Using A Generic Class with a Type Constraint Pin
Gerry Schmitz30-May-17 13:08
mveGerry Schmitz30-May-17 13:08 
GeneralRe: Using A Generic Class with a Type Constraint Pin
Richard Andrew x6430-May-17 14:30
professionalRichard Andrew x6430-May-17 14:30 
QuestionWinform taskbar thumbnail problem Pin
Member 1322816728-May-17 21:37
Member 1322816728-May-17 21:37 
QuestionRe: Winform taskbar thumbnail problem Pin
Maciej Los29-May-17 2:31
mveMaciej Los29-May-17 2:31 
AnswerRe: Winform taskbar thumbnail problem Pin
Dave Kreskowiak29-May-17 2:41
mveDave Kreskowiak29-May-17 2:41 
Questioncalling a string variable in "proc.StartInfo.Arguments" Pin
Member 1322808028-May-17 20:02
Member 1322808028-May-17 20:02 
AnswerRe: calling a string variable in "proc.StartInfo.Arguments" Pin
OriginalGriff28-May-17 20:25
mveOriginalGriff28-May-17 20:25 
GeneralRe: calling a string variable in "proc.StartInfo.Arguments" Pin
Member 1322808028-May-17 20:40
Member 1322808028-May-17 20:40 
AnswerRe: calling a string variable in "proc.StartInfo.Arguments" Pin
Ralf Meier28-May-17 21:13
mveRalf Meier28-May-17 21:13 
GeneralRe: calling a string variable in "proc.StartInfo.Arguments" Pin
OriginalGriff28-May-17 21:34
mveOriginalGriff28-May-17 21:34 
GeneralRe: calling a string variable in "proc.StartInfo.Arguments" Pin
Richard MacCutchan28-May-17 21:37
mveRichard MacCutchan28-May-17 21:37 
QuestionDeclaring a Generic Class Pin
Richard Andrew x6428-May-17 14:50
professionalRichard Andrew x6428-May-17 14:50 
AnswerRe: Declaring a Generic Class PinPopular
OriginalGriff28-May-17 19:28
mveOriginalGriff28-May-17 19:28 

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.