.class

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2006
Posts: 137
Reputation: PoovenM is on a distinguished road 
Solved Threads: 11
PoovenM PoovenM is offline Offline
Junior Poster

.class

 
0
  #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!
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: .class

 
0
  #2
Dec 10th, 2007
That's a type of reflection methods in JAVA, actually C# treats with System.Type not System.Class like

  1. Type[] types = new Type[10];
  2. types[0] = System.String;
  3. types[1] = System.TextBox;
  4. .....
Last edited by Ramy Mahrous; Dec 10th, 2007 at 10:52 am.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 137
Reputation: PoovenM is on a distinguished road 
Solved Threads: 11
PoovenM PoovenM is offline Offline
Junior Poster

Re: .class

 
0
  #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 11:02 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: .class

 
0
  #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
  1. 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....
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 137
Reputation: PoovenM is on a distinguished road 
Solved Threads: 11
PoovenM PoovenM is offline Offline
Junior Poster

Re: .class

 
0
  #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 2:39 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC