Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
Questionhow to check vaild email address? Pin
ATHIRA S28-Sep-14 20:21
ATHIRA S28-Sep-14 20:21 
AnswerRe: how to check vaild email address? Pin
BillWoodruff28-Sep-14 20:37
professionalBillWoodruff28-Sep-14 20:37 
SuggestionRe: how to check vaild email address? Pin
Kornfeld Eliyahu Peter28-Sep-14 21:01
professionalKornfeld Eliyahu Peter28-Sep-14 21:01 
AnswerRe: how to check vaild email address? Pin
Bernhard Hiller28-Sep-14 22:03
Bernhard Hiller28-Sep-14 22:03 
GeneralRe: how to check vaild email address? Pin
Pete O'Hanlon28-Sep-14 22:15
mvePete O'Hanlon28-Sep-14 22:15 
GeneralRe: how to check vaild email address? Pin
Richard Deeming29-Sep-14 1:42
mveRichard Deeming29-Sep-14 1:42 
AnswerRe: how to check vaild email address? Pin
jschell29-Sep-14 7:49
jschell29-Sep-14 7:49 
Questioninvoke method in derived classes vs. invoke method in base class: C# language question Pin
BillWoodruff27-Sep-14 21:56
professionalBillWoodruff27-Sep-14 21:56 
Recently a question on QA (from a newbie) asked about the best way to selectively invoke a method in either a base class containing the method, or a class derived from the base class containing an identically named and identically functional method ... in another method that took as a parameter an instance of either the base class, or any of its derived types.

Consider the following classes:
C#
public class BaseClass
{
    public void ShowMe() {MessageBox.Show("BaseClass");}
}

public class DerivedClass1: BaseClass
{
    public void ShowMe(){MessageBox.Show("DerivedClass1");}
}
    
public class DerivedClass2: BaseClass 
{ 
    public void ShowMe(){MessageBox.Show("DerivedClass2");}
}
And, consider the following example using instnaces of the classes:
BaseClass baseClass = new BaseClass();
DerivedClass1 derivedClass1 = new DerivedClass1();
DerivedClass2 derivedClass2 = new DerivedClass2();

private void invokeClassMethod1(BaseClass theClass) {theClass.ShowMe();}
    
private void invokeClassMethod2(dynamic theClass) { theClass.ShowMe(); }
    
private void invokeClassMethod3(BaseClass theClass)
{
    if(theClass is DerivedClass1)
    {
        (theClass as DerivedClass1).ShowMe();
    } else if (theClass is DerivedClass2)
    {
        (theClass as DerivedClass2).ShowMe();
    }
    else
    {
        theClass.ShowMe();
    }
}
Obviously, 'invokeClassMethod1 will always invoke the method 'ShowMe in the BaseClass instance.

'invokeClassMethod2 uses 'dynamic declaration of the parameter Type, and "does the right thing" to invoke either the base class method, or the derived type method.

'invokeClassMethod3 does an identity check and invokes the "right" method.

Equally obvious is that this scenario calls for a restructuring of the code to declare the method in the BaseClass of type 'virtual, and to then over-ride the method in the derived classes which would then automatically invoke the right target.

The question is: what's the cost (performance, memory use, possible "risks: threading ? extensibility ? security ?) of using 'dynamic in this example compared to declaring the method in the BaseClass 'virtual and over-riding it ?
« I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant

AnswerRe: invoke method in derived classes vs. invoke method in base class: C# language question Pin
Kornfeld Eliyahu Peter27-Sep-14 22:47
professionalKornfeld Eliyahu Peter27-Sep-14 22:47 
GeneralRe: invoke method in derived classes vs. invoke method in base class: C# language question Pin
BillWoodruff27-Sep-14 23:44
professionalBillWoodruff27-Sep-14 23:44 
AnswerRe: invoke method in derived classes vs. invoke method in base class: C# language question Pin
Kornfeld Eliyahu Peter27-Sep-14 23:55
professionalKornfeld Eliyahu Peter27-Sep-14 23:55 
GeneralRe: invoke method in derived classes vs. invoke method in base class: C# language question Pin
Richard Deeming29-Sep-14 1:40
mveRichard Deeming29-Sep-14 1:40 
AnswerRe: invoke method in derived classes vs. invoke method in base class: C# language question Pin
Kornfeld Eliyahu Peter29-Sep-14 2:06
professionalKornfeld Eliyahu Peter29-Sep-14 2:06 
Questionexecuting multiple sql select queries in ms access using c# Pin
nishadamit9027-Sep-14 21:32
nishadamit9027-Sep-14 21:32 
QuestionXSD question... Pin
SledgeHammer0126-Sep-14 15:41
SledgeHammer0126-Sep-14 15:41 
QuestionRe: XSD question... Pin
Richard MacCutchan26-Sep-14 21:37
mveRichard MacCutchan26-Sep-14 21:37 
QuestionRe: XSD question... Pin
George Jonsson27-Sep-14 3:55
professionalGeorge Jonsson27-Sep-14 3:55 
AnswerRe: XSD question... Pin
SledgeHammer0127-Sep-14 6:26
SledgeHammer0127-Sep-14 6:26 
AnswerRe: XSD question... Pin
George Jonsson27-Sep-14 13:21
professionalGeorge Jonsson27-Sep-14 13:21 
GeneralRe: XSD question... Pin
SledgeHammer0127-Sep-14 14:21
SledgeHammer0127-Sep-14 14:21 
GeneralRe: XSD question... Pin
George Jonsson27-Sep-14 15:13
professionalGeorge Jonsson27-Sep-14 15:13 
GeneralRe: XSD question... Pin
SledgeHammer0127-Sep-14 16:00
SledgeHammer0127-Sep-14 16:00 
GeneralRe: XSD question... Pin
George Jonsson27-Sep-14 20:21
professionalGeorge Jonsson27-Sep-14 20:21 
GeneralRe: XSD question... Pin
SledgeHammer0128-Sep-14 7:10
SledgeHammer0128-Sep-14 7:10 
QuestionRecommendations on VB.Net to C# code conversion tool Pin
Vipul Mehta26-Sep-14 8:31
Vipul Mehta26-Sep-14 8:31 

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.