PC Review


Reply
Thread Tools Rate Thread

Re: Need to check if two objects are compatible types

 
 
Magnus Lidbom
Guest
Posts: n/a
 
      3rd Feb 2004

"markusszil" <(E-Mail Removed)> wrote in message
news:98854780-B727-4E69-BD20-(E-Mail Removed)...
> Hello all,
>
> (What may well be a)
> Dumb Question:
>
> How do I determine if 2 objects are of equivalent type? I need an

expression which evaluates true if left-hand-side of comparison is of same
type or inherits from rhs.
>
> I was hoping to use "is" or "as" but these seem to require explicit type

names, they can't use type objects.
>
> Some pseudo C# showing what I would like:
>
> public class ClassA { }
> public class ClassB:ClassA{ }
>
> ClassA a=new ClassA();
> ClassB b=new ClassB();
>
> if (b is ClassA) { } // this works and, in this case, should

evaluate true
>
> if (b is a.GetType()) { } // this is what I want, but this line

generates syntax error - a is not a type
>


if(a.GetType().IsAssignableFrom(b.GetType()))
{
//Whatever
}

Regards /Magnus Lidbom


 
Reply With Quote
 
 
 
 
=?Utf-8?B?bWFya3Vzc3ppbA==?=
Guest
Posts: n/a
 
      3rd Feb 2004
Thanks - worked great.

Markus

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple join types in one query, jet compatible, exec from Excel/ John Mulford Microsoft Access Queries 3 21st Aug 2008 06:06 PM
Array Objects pointers, value types reference types?? plau011@hotmail.com Microsoft VB .NET 1 10th Feb 2006 01:32 AM
Which audio file types are compatible with PowerPoint 2002? =?Utf-8?B?QW5uZXR0ZVM=?= Microsoft Powerpoint 2 7th Jan 2006 07:33 PM
Compatible Audio file types =?Utf-8?B?TWlrZUI=?= Windows XP MovieMaker 2 4th Nov 2005 09:58 PM
Excel97 chart objects compatible with Excel2000 chart objects Vivekananda Microsoft Excel Charting 1 27th Feb 2004 07:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:33 PM.