473,385 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

long versus Long?

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
Apr 22 '07 #1
6 18043
Ikke wrote:
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
Apr 22 '07 #2
Hello!
You wrote on Sun, 22 Apr 2007 13:55:07 GMT:

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

System.Int64?

With best regards,
Eugene Mayevski
http://www.SecureBlackbox.com - the comprehensive component suite for
network security

Apr 22 '07 #3
Arne Vajhøj <ar**@vajhoej.dkwrote in
news:46***********************@news.sunsite.dk:

<snip>
>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
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
Apr 22 '07 #4
read up on "boxing". Anytime, a value type is passed into something that is
expecting an object the CLR will implicitly convert it to an object.
http://en.csharp-online.net/Glossary...ition_-_Boxing

"Ikke" <ik**@hier.bewrote in message
news:Xn************************@195.130.132.70...
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

Apr 22 '07 #5
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 Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ikke" <ik**@hier.bewrote in message
news:Xn************************@195.130.132.70...
Arne Vajhøj <ar**@vajhoej.dkwrote in
news:46***********************@news.sunsite.dk:

<snip>
>>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

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

Apr 22 '07 #6
Nicholas Paldino [.NET/C# MVP] wrote:
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
Apr 22 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Noen | last post by:
def XOR(s1,s2): """ XOR string s1 with s2 """ output = "" # Argument check if (type(s1) and type(s2)) != type(""): raise TypeError, "Arguments are not strings" if len(s1) != len(s2): raise...
3
by: TPJ | last post by:
"The advantage of xrange() over range() is minimal (since xrange() still has to create the values when asked for them) except when a very large range is used on a memory-starved machine or when all...
65
by: kyle.tk | last post by:
I am trying to write a function to convert an ipv4 address that is held in the string char *ip to its long value equivalent. Here is what I have right now, but I can't seem to get it to work. ...
11
by: Martin Joergensen | last post by:
Hi, I've encountered a really, *really*, REALLY strange error :-) I have a for-loop and after 8 runs I get strange results...... I mean: A really strange result.... I'm calculating...
8
by: ronrsr | last post by:
I have a single long string - I'd like to split it into a list of unique keywords. Sadly, the database wasn't designed to do this, so I must do this in Python - I'm having some trouble using the...
4
by: aj | last post by:
DB2 8.2 LUW FP14 Is there any real difference between select blahblahblah... where blah IN (select blah......) versus select blahblahblah... where blah = ANY (select blah.....) versus select...
2
by: snorble | last post by:
I started creating a simple "bits" class, intended to act like a array of bits. This was my initial idea, basically just overriding the string representation to display the bitmask (so far): ...
11
by: =?Utf-8?B?U3VqZWV0?= | last post by:
If there are long strings (like 1MB or 2MB) is it more performant to pass those by ref to methods or by value?
4
by: eacollie | last post by:
Hi: I'm running into an overflow problem with the following code (with the variable nCNOS), but get a compile error (AddInvoice rsInvoice, nRNOS, nCNOS) if I change it to Long. Can someone help?...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.