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

C#

 
GeneralRe: Dynamic Casting (Runtime) Pin
David Stone10-Feb-03 17:55
sitebuilderDavid Stone10-Feb-03 17:55 
GeneralRe: Dynamic Casting (Runtime) Pin
Christian Graus10-Feb-03 18:05
protectorChristian Graus10-Feb-03 18:05 
GeneralRe: Dynamic Casting (Runtime) Pin
David Stone10-Feb-03 18:17
sitebuilderDavid Stone10-Feb-03 18:17 
GeneralRe: Dynamic Casting (Runtime) Pin
Christian Graus10-Feb-03 19:03
protectorChristian Graus10-Feb-03 19:03 
GeneralRe: Dynamic Casting (Runtime) Pin
David Stone10-Feb-03 19:10
sitebuilderDavid Stone10-Feb-03 19:10 
GeneralRe: Dynamic Casting (Runtime) Pin
Anonymous10-Feb-03 17:17
Anonymous10-Feb-03 17:17 
GeneralRe: Dynamic Casting (Runtime) Pin
mgarwood11-Feb-03 2:36
mgarwood11-Feb-03 2:36 
GeneralRe: Dynamic Casting (Runtime) Pin
David Stone11-Feb-03 3:26
sitebuilderDavid Stone11-Feb-03 3:26 
Actually, the IComparable interface isn't going to help you. The CompareTo() method returns an int. It's for sorting lists.

You should however, use the "is" keyword in order to find out if it "is" an instance of that class. Don't use GetType() typeof() or even CompareTo(). Let's say you had a function that looked like this:
public void Cast(object obj)
{
      if(obj is OneType)
      {
         OneType castedType = (OneType)obj;
         //Do other stuff appropriate to OneType in here
      {
      else if(obj is AnotherType)
      {
         AnotherType castedType = (AnotherType)obj;
         //Do other stuff appropriate to AnotherType in here
      {
      return;
}


If you really want dynamic casting, this is the way to do it. Using IComparable is not.

Hope that's clearer now. Smile | :)


Hey, what can I say? I'm a chick magnet...a babe conductor...a logarithm for the ladies.
-Strong Bad from HomeStarRunner.com


Essential Tips for Web Developers


GeneralRe: Dynamic Casting (Runtime) Pin
leppie11-Feb-03 7:30
leppie11-Feb-03 7:30 
GeneralRe: Dynamic Casting (Runtime) Pin
mgarwood11-Feb-03 9:18
mgarwood11-Feb-03 9:18 
General#iclude problems Pin
mehere10-Feb-03 14:51
mehere10-Feb-03 14:51 
GeneralRe: #iclude problems Pin
Christian Graus10-Feb-03 15:17
protectorChristian Graus10-Feb-03 15:17 
GeneralRe: #iclude problems Pin
mehere10-Feb-03 18:08
mehere10-Feb-03 18:08 
GeneralRe: #iclude problems Pin
David Stone10-Feb-03 18:22
sitebuilderDavid Stone10-Feb-03 18:22 
GeneralRe: #iclude problems Pin
Stephane Rodriguez.10-Feb-03 19:01
Stephane Rodriguez.10-Feb-03 19:01 
GeneralRe: #iclude problems Pin
David Stone10-Feb-03 19:04
sitebuilderDavid Stone10-Feb-03 19:04 
GeneralRe: #iclude problems Pin
mehere10-Feb-03 22:43
mehere10-Feb-03 22:43 
GeneralRegex problem across muliple lines Pin
Giles10-Feb-03 12:06
Giles10-Feb-03 12:06 
GeneralRe: Regex problem across muliple lines Pin
Anonymous10-Feb-03 17:14
Anonymous10-Feb-03 17:14 
Generalsubclassed controls Pin
vlusardi10-Feb-03 9:55
vlusardi10-Feb-03 9:55 
GeneralRe: subclassed controls Pin
leppie10-Feb-03 10:10
leppie10-Feb-03 10:10 
GeneralRe: subclassed controls Pin
vlusardi10-Feb-03 11:06
vlusardi10-Feb-03 11:06 
GeneralCOM+ in .NET::C# & DLLs Pin
sss_dr10-Feb-03 8:23
sss_dr10-Feb-03 8:23 
GeneralOwner Draw... Pin
Yuval Kaplan10-Feb-03 1:56
Yuval Kaplan10-Feb-03 1:56 
GeneralRe: Owner Draw... Pin
TigerNinja_10-Feb-03 2:40
TigerNinja_10-Feb-03 2:40 

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.