long versus Long?

  • Thread starter Thread starter Ikke
  • Start date Start date
I

Ikke

Hi everybody,

Coming from a Java background, I'm used to having a "long" type and a
"Long" Object around...

I've recently started a simple, small C# project, and I'm looking for a way
to pass a long value to a method, which only accepts an Object. Logically,
I can't pass the long value so I started looking for a Long Object. But I
can't seem to find it!

Is there such a thing as a Long Object in C#, and if not, how do I solve
this problem?

Thanks,

Ikke
 
Hello!
You wrote on Sun, 22 Apr 2007 13:55:07 GMT:

I> Is there such a thing as a Long Object in C#, and if not, how do I solve
I> this problem?

System.Int64?

With best regards,
Eugene Mayevski
http://www.SecureBlackbox.com - the comprehensive component suite for
network security
 
Ikke said:
Coming from a Java background, I'm used to having a "long" type and a
"Long" Object around...

I've recently started a simple, small C# project, and I'm looking for a way
to pass a long value to a method, which only accepts an Object. Logically,
I can't pass the long value so I started looking for a Long Object. But I
can't seem to find it!

Is there such a thing as a Long Object in C#, and if not, how do I solve
this problem?

1) you can pass a long to something that expects an object

2) long has an alias System.Int64, which is probably the closest
to java.lang.Long you can find, but note that long is an alias
for System.Int64, System.Int64 is not a wrapper around long

Arne
 
1) you can pass a long to something that expects an object

2) long has an alias System.Int64, which is probably the closest
to java.lang.Long you can find, but note that long is an alias
for System.Int64, System.Int64 is not a wrapper around long

Arne

I think the first option is the best for this particular case, but it's
nice to know about option 2.

Thanks, Arne & Eugene for both your quick replies!

Ikke
 
It should be noted that long in C# is NOT the same, or even close to the
Long object in java.

When something expects an object, you can pass a long to it, and the
value type is boxed, meaning that a reference type object is created and the
value type stored in it. The process of getting the value type back from
the object reference is called unboxing.

This is very, very different from the Long object in Java, which is
actually a typed wrapper which allows pass by reference semantics. If you
are looking for something similar in .NET, you are going to have to code it
yourself.

Hope this helps.
 
Nicholas said:
It should be noted that long in C# is NOT the same, or even close to the
Long object in java.

When something expects an object, you can pass a long to it, and the
value type is boxed, meaning that a reference type object is created and the
value type stored in it. The process of getting the value type back from
the object reference is called unboxing.

This is very, very different from the Long object in Java, which is
actually a typed wrapper which allows pass by reference semantics. If you
are looking for something similar in .NET, you are going to have to code it
yourself.

Calling with a java.lang.Long will pass a reference by value which
refer to an immutable object.

Not much by reference semantics in that.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top