Class Identification (Class Name) 
Author Message
 Class Identification (Class Name)

Say I have a class called Person

I can then write
Person o = new Person()

But how do I do this?
if  0 == Person     ?
another word of want to test if o is of class Person

__Allan



Sun, 21 Nov 2004 12:27:23 GMT  
 Class Identification (Class Name)

Quote:
> I can then write
> Person o = new Person()

> But how do I do this?
> if  0 == Person     ?
> another word of want to test if o is of class Person

if you want to be able to identify whether an object has some type, you use
the magic word 'is':

if (o is Person)
  MessageBox.Show ( "o is of type Person");



Sun, 21 Nov 2004 14:39:57 GMT  
 Class Identification (Class Name)
If I understand your problem correctly, either use

if (o is Person)        for a test whether o is from type Person or derived
from Person
or
if (o.GetType() == typeof(Person))        for a test whether o is exactly of
type Person.

hope this helps

Jrg


Quote:
> Say I have a class called Person

> I can then write
> Person o = new Person()

> But how do I do this?
> if  0 == Person     ?
> another word of want to test if o is of class Person

> __Allan



Sun, 21 Nov 2004 14:50:35 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. class class-name: base-class : interface

2. Class from a string that contains the name of the class

3. Class in class OR class derived from class?

4. How to set app name and class name

5. how to get a window's class name and window name

6. Identification of the duplicate file by name

7. Web Services: Proxy class make own class definition for user class

8. Class Wizard won't let me derive a class from my class

9. Trying to add a class with no base class in Class Wizard

10. class design: Class.ToString() ro Class.Value?

11. looking for class structure differences between smalltalk class and c# class

12. Is it possible to call a class method if the class name and method name are in a variable ?

 

 
Powered by phpBB® Forum Software