HighTechTalks DotNet Forums  

Re: int Data Type, Primitive or Not?

Dotnet VJSharp microsoft.public.dotnet.vjsharp


Discuss Re: int Data Type, Primitive or Not? in the Dotnet VJSharp forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Bruno Jouhier [MVP]
 
Posts: n/a

Default Re: int Data Type, Primitive or Not? - 08-25-2004 , 01:36 PM







"Nate Laws" <Nate Laws (AT) discussions (DOT) microsoft.com> a écrit dans le message de
news: 86C67EBD-BAC0-4095-97D3-4BEE013C15A9...soft (DOT) com...
Quote:
The reason I ask is because I need a way to pass an integer to
Microsoft.Office.Interop.Excel.SeriesCollection.It em(Object)

In C#, int is aliased to System.Int32 so doing something like
SeriesCollection.Item(1) works fine.

However, in J# this will not even compile, and doing something like
SeriesCollection.Item(new Integer("1")) throws a "Item method of
SeriesCollection class failed" exception for me.

Thanks,
Nate

In J#, int is not a complete alias to System.Int32. The compiler
distinguishes the two as follows:

int is a primitive type and is not directly assignable to Object (so that J#
does not break the Java specs)
System.Int32 is the .NET boxed version of int, and it is directly assignable
to Object (here, we don't care about the Java specs because System.Int32
does not belong to the Java world).

Also, System.Int32 and java.lang.Integer are different classes. The first
one gives you .NET boxing (and works with .NET reflection for example), the
second one gives you Java boxing (and works with java.lang.reflect classes).

So, you have two ways to box an int in J#:

(System.Int32)i gives you .NET boxing
new Integer(i) gives you Java boxing

For you Excel interop problem, you should try
SeriesCollection.Item((System.Int32)1).

Bruno.




Reply With Quote
  #2  
Old   
Bruno Jouhier [MVP]
 
Posts: n/a

Default Re: int Data Type, Primitive or Not? - 08-25-2004 , 04:03 PM






Thanks for testing it :-).

Bruno.

"Lars-Inge Tønnessen [VJ# MVP]" <http://emailme.larsinge.com> a écrit dans
le message de news: eRwdd7siEHA.4020 (AT) TK2MSFTNGP10 (DOT) phx.gbl...
Quote:
For you Excel interop problem, you should try
SeriesCollection.Item((System.Int32)1).


I did a small test, yes Bruno this will work. =)


Cheers,
Lars-Inge





Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.