Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / JScript / September 2003

Tip: Looking for answers? Try searching our database.

A better typeof operator?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Agendum - 23 Sep 2003 07:09 GMT
The JScript.NET typeof operator returns a String... are there any plans to
make an operator which returns a "System.Type"?  It would be very useful,
for instance:

var list : ArrayList = new ArrayList();
...
return MyClass[](list.ToArray(typeof(MyClass)));

Currently, the only way I found to accomplish this is if I am able to make
an instance of MyClass to call the GetType() method:

var list : ArrayList = new ArrayList();
...
var temp : MyClass = new MyClass();
return MyClass[](list.ToArray(temp.GetType()));

But sometimes, this just isn't possible... i.e. the MyClass constructor does
something I do not want executed.  There are ways to work around that even,
but then its just getting messy when all I want is a working typeof
operator.
Peter Torr \(MS\) - 24 Sep 2003 17:14 GMT
> The JScript.NET typeof operator returns a String... are there any plans to
> make an operator which returns a "System.Type"?  It would be very useful,
> for instance:

Why not just give it MyClass itself?

   return MyClass[](list.ToArray(MyClass));

or, to make it a bit clearer:

   var type : Type = MyClass
   return MyClass[](list.ToArray(type));

In JScript, types are just values, like strings or numbers. You are probably
used to VB which only lets you use types in special contexts (and thus has
weird syntax for dealing with them). So no special operator is needed.

Both typeof (which is there for back-compat and is pretty useless) and
GetType() are for getting the type of an instance.

Peter

Signature

Please post questions to the newsgroup - everyone benefits.
This post is provided "AS IS" with no warranties, and confers no rights
Sample code subject to http://www.microsoft.com/info/cpyright.htm
Bore yourself to tears -- http://blogs.gotdotnet.com/ptorr


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.