Click here to Skip to main content
15,894,896 members
Home / Discussions / C#
   

C#

 
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 
AnswerRe: Using A Generic Class with a Type Constraint Pin
OriginalGriff29-May-17 22:24
mveOriginalGriff29-May-17 22:24 
The problem is that the two lists aren't covariant.
What that basically means is that if you construct collections:
C#
class Animal {...}
class Ape : Animal {...}
class Feline : Animal {...}
 
List<Ape> apes = new List<Ape>();
List<Feline> cats = new List<Feline>();
List<Animal> animals = new List<Animal>();
Then because an Ape is an Animal, you can add a new species to either collection:
C#
Ape newSpecies = new Ape("Pans Sapiens");
apes.Add(newSpecies);
animals.Add(newSpecies);

But if you try to add it to the Felines:
C#
cats.Add(newSpecies);

You will get a compilation error:
Argument 1: cannot convert from 'GeneralTesting.frmMain.Ape' to 'GeneralTesting.frmMain.Feline'

And that is what you would expect.
But ... if you could do what you want, you could do this:
C#
Ape newSpecies = new Ape("Pans Sapiens");
animals = cats;
animals.Add(newSpecies);

And you would have an Ape in your Feline collection - which means your application will crash later on when you try to use it.

What you are passing to the AddBusinessObjectList is not a BusinessObjectList<BusinessObjectBase> - it's a derived list of a derived class.

I'm not sure exactly what you can do about this - it may be possible to construct a cast operator, but I'm not sure if that would work without some serious head scratching!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!

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 
GeneralRe: Declaring a Generic Class Pin
Richard Andrew x6429-May-17 2:09
professionalRichard Andrew x6429-May-17 2:09 

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.