User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 423,532 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 4,348 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: 430 | Replies: 4 | Solved
Reply
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 106
Reputation: PoovenM is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 8
PoovenM PoovenM is offline Offline
Junior Poster

Question .class

  #1  
Dec 10th, 2007
Hey guys,

I was wondering, in Java the following is allowed:

  1. Class[] classList = new Class[10];
  2. classList[0] = System.class;

Can this be done in C#?

Thanks!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2006
Location: Egypt
Posts: 762
Reputation: RamyMahrous is on a distinguished road 
Rep Power: 4
Solved Threads: 59
Featured Poster
RamyMahrous's Avatar
RamyMahrous RamyMahrous is offline Offline
Master Poster

Re: .class

  #2  
Dec 10th, 2007
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/
Reply With Quote  
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 106
Reputation: PoovenM is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 8
PoovenM PoovenM is offline Offline
Junior Poster

Question Re: .class

  #3  
Dec 10th, 2007
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:

  1. Type[] classList = ...
  2. WTTag tag = ...
  3. for (int k = 0; k < classList.Length; k++)
  4. if (tag is classList[k])
  5. ...

Would this be valid
Last edited by PoovenM : Dec 10th, 2007 at 10:02 am.
Reply With Quote  
Join Date: Aug 2006
Location: Egypt
Posts: 762
Reputation: RamyMahrous is on a distinguished road 
Rep Power: 4
Solved Threads: 59
Featured Poster
RamyMahrous's Avatar
RamyMahrous RamyMahrous is offline Offline
Master Poster

Re: .class

  #4  
Dec 10th, 2007
Any class, interface, struct, enum or delegate is Type.

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/
Reply With Quote  
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 106
Reputation: PoovenM is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 8
PoovenM PoovenM is offline Offline
Junior Poster

Re: .class

  #5  
Dec 11th, 2007
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:
  1. Type classType = MyClassName;
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:
  1. Type classType = System.String;
  2. String hello;
  3. if (hello is classType) ...
I actually get a compile error (in the first line) so I guess that answers my question. Thanks again hey!
Last edited by PoovenM : Dec 11th, 2007 at 1:39 am.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C# Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C# Forum

All times are GMT -4. The time now is 5:24 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC