Click here to Skip to main content
15,902,939 members
Home / Discussions / C#
   

C#

 
AnswerRe: Windows Tab Control Flickering Pin
Abhinav S1-Dec-10 1:42
Abhinav S1-Dec-10 1:42 
QuestionSwitching on type Pin
creatiive30-Nov-10 23:44
creatiive30-Nov-10 23:44 
AnswerRe: Switching on type Pin
phil.o1-Dec-10 0:01
professionalphil.o1-Dec-10 0:01 
AnswerRe: Switching on type Pin
Pete O'Hanlon1-Dec-10 0:49
mvePete O'Hanlon1-Dec-10 0:49 
AnswerRe: Switching on type Pin
musefan1-Dec-10 1:01
musefan1-Dec-10 1:01 
GeneralRe: Switching on type Pin
creatiive1-Dec-10 2:34
creatiive1-Dec-10 2:34 
GeneralRe: Switching on type Pin
musefan1-Dec-10 2:55
musefan1-Dec-10 2:55 
AnswerRe: Switching on type Pin
Keith Barrow1-Dec-10 1:18
professionalKeith Barrow1-Dec-10 1:18 
I'm just doing the schoolboy error check, so don't take this amiss, are you sure you haven't really got:
AbsMyObject.MyMethod(); 

I.E. The method really belongs in the AbsMyObject class rather than the caller?

Also I tried this (to make sure I wasn't about to make a schoolboy error Smile | :) ) and it works without the cast:
public abstract class Foo { }
public class Bar : Foo { }
public class Baz : Foo { }
public class Qux : Baz { }
public class Quux : Foo { }

class Program
{
    static void MyMethod(string id, Foo arg) { Console.WriteLine("{0} Called Object Type {1}", id, arg.GetType()); }
    static void MyMethod(Foo arg) { MyMethod("Foo", arg); }
    static void MyMethod(Bar arg) { MyMethod("Bar", arg); }
    static void MyMethod(Baz arg) { MyMethod("Baz", arg); }

    static void Main(string[] args)
    {
        MyMethod(new Bar());
        MyMethod(new Baz());
        MyMethod(new Qux());
        MyMethod(new Quux());
        Console.ReadLine();
    }
}


Sorry if I misunderstood your problem, but you are right, such if statements have a bad code smell. [Edit]: If those two options don't apply, Pete's suggestion is good. Can MyMethod be refactored to accept the base class and handle the class based differences inside it?

GeneralRe: Switching on type Pin
musefan1-Dec-10 1:24
musefan1-Dec-10 1:24 
GeneralRe: Switching on type Pin
Keith Barrow1-Dec-10 1:52
professionalKeith Barrow1-Dec-10 1:52 
GeneralRe: Switching on type Pin
PIEBALDconsult1-Dec-10 2:26
mvePIEBALDconsult1-Dec-10 2:26 
GeneralRe: Switching on type Pin
Pete O'Hanlon1-Dec-10 2:57
mvePete O'Hanlon1-Dec-10 2:57 
AnswerRe: Switching on type Pin
PIEBALDconsult1-Dec-10 2:28
mvePIEBALDconsult1-Dec-10 2:28 
QuestionCall XP Mode shortcut programmatically [modified] Pin
spif200130-Nov-10 20:36
spif200130-Nov-10 20:36 
AnswerRe: Call XP Mode shortcut programmatically Pin
Rajesh Anuhya30-Nov-10 22:27
professionalRajesh Anuhya30-Nov-10 22:27 
GeneralRe: Call XP Mode shortcut programmatically Pin
spif200130-Nov-10 22:35
spif200130-Nov-10 22:35 
AnswerRe: Call XP Mode shortcut programmatically Pin
Eddy Vluggen1-Dec-10 1:23
professionalEddy Vluggen1-Dec-10 1:23 
GeneralRe: Call XP Mode shortcut programmatically Pin
spif20011-Dec-10 1:52
spif20011-Dec-10 1:52 
GeneralRe: Call XP Mode shortcut programmatically Pin
Eddy Vluggen1-Dec-10 2:32
professionalEddy Vluggen1-Dec-10 2:32 
QuestionMultiple query results on one form. Pin
Joe Stansfield30-Nov-10 18:36
Joe Stansfield30-Nov-10 18:36 
AnswerRe: Multiple query results on one form. Pin
Pete O'Hanlon30-Nov-10 22:23
mvePete O'Hanlon30-Nov-10 22:23 
GeneralRe: Multiple query results on one form. Pin
Joe Stansfield1-Dec-10 11:29
Joe Stansfield1-Dec-10 11:29 
Questionin microsoft report viewer i want change datasource in run time Pin
Nabawoka30-Nov-10 10:18
Nabawoka30-Nov-10 10:18 
AnswerRe: in microsoft report viewer i want change datasource in run time Pin
Pete O'Hanlon30-Nov-10 11:32
mvePete O'Hanlon30-Nov-10 11:32 
GeneralRe: in microsoft report viewer i want change datasource in run time Pin
Nabawoka30-Nov-10 19:24
Nabawoka30-Nov-10 19:24 

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.