•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 427,188 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,203 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser: Programming Forums
Views: 437 | Replies: 4 | Solved
![]() |
•
•
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 107
Reputation:
Rep Power: 3
Solved Threads: 8
Hey guys,
I was wondering, in Java the following is allowed:
Can this be done in C#?
Thanks!
I was wondering, in Java the following is allowed:
java Syntax (Toggle Plain Text)
Class[] classList = new Class[10]; classList[0] = System.class;
Can this be done in C#?
Thanks!
That's a type of reflection methods in JAVA, actually C# treats with System.Type not System.Class like
Type[] types = new Type[10]; types[0] = System.String; types[1] = System.TextBox; .....
Last edited by RamyMahrous : Dec 10th, 2007 at 9:52 am.
B.Sc Computer Science, Helwan University
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
•
•
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 107
Reputation:
Rep Power: 3
Solved Threads: 8
I was thinking I'd have to use the Type class but I wasn't sure how I'd get the 'type' of the class into the array. Thanks Remy!!
I was wondering, would the following situation be possible?
I have an object that can be one of several classes, however only a certain subset of these class are accpetable. I was thinking that the following might be possible:
Would this be valid
I have an object that can be one of several classes, however only a certain subset of these class are accpetable. I was thinking that the following might be possible:
C# Syntax (Toggle Plain Text)
Type[] classList = ... WTTag tag = ... for (int k = 0; k < classList.Length; k++) if (tag is classList[k]) ...
Would this be valid
Last edited by PoovenM : Dec 10th, 2007 at 10:02 am.
Any class, interface, struct, enum or delegate is Type.
Your code is wrong as 'is' take a type not an instance; like
Your logic isn't right as classList carries instances from one type so loop won't be useful as classList[0] like classList[1] like classList[2] like....
Your code is wrong as 'is' take a type not an instance; like
if (tag is WTTag) .....
Your logic isn't right as classList carries instances from one type so loop won't be useful as classList[0] like classList[1] like classList[2] like....
B.Sc Computer Science, Helwan University
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
•
•
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 107
Reputation:
Rep Power: 3
Solved Threads: 8
I'm not sure I fully understand Ramy; so all my classes have a Type. This Type is unique to a class and is similar to the ClassName.class attribute in Java? Except that a Type is implicately accessed:
The as operator takes an object and determines if it is an instance of a particular class right? If this is the case then based on what you've said, when I stored the 'Type' of a class in the array I don't really store enough information about the class to do an is comparison? That is, in general the following will not work:
I actually get a compile error (in the first line) so I guess that answers my question. Thanks again hey!
C# Syntax (Toggle Plain Text)
Type classType = MyClassName;
C# Syntax (Toggle Plain Text)
Type classType = System.String; String hello; if (hello is classType) ...
Last edited by PoovenM : Dec 11th, 2007 at 1:39 am.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C# Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- java and using observable class (Java)
- Accessing functions from base class (C)
- Circle class (C++)
- "missing storage-class or type specifiers" error (C++)
- first math class in uni (Geeks' Lounge)
Other Threads in the C# Forum
- Previous Thread: how to update profile of login member
- Next Thread: numbering code lines in IDE


Linear Mode