long versus Long?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ikke

    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
  • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

    #2
    Re: long versus Long?

    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

    Comment

    • Eugene Mayevski

      #3
      Re: long versus Long?

      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

      Comment

      • Ikke

        #4
        Re: long versus Long?

        Arne Vajhøj <arne@vajhoej.d kwrote in
        news:462b6c51$0 $90269$14726298 @news.sunsite.d k:

        <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

        Comment

        • Jeff Jarrell

          #5
          Re: long versus Long?

          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.




          "Ikke" <ikke@hier.bewr ote in message
          news:Xns991AA23 CC8FCEikkehierb e@195.130.132.7 0...
          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

          Comment

          • Nicholas Paldino [.NET/C# MVP]

            #6
            Re: long versus Long?

            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]
            - mvp@spam.guard. caspershouse.co m

            "Ikke" <ikke@hier.bewr ote in message
            news:Xns991AA60 9C3E0Eikkehierb e@195.130.132.7 0...
            Arne Vajhøj <arne@vajhoej.d kwrote in
            news:462b6c51$0 $90269$14726298 @news.sunsite.d k:
            >
            <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

            Comment

            • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

              #7
              Re: long versus Long?

              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

              Comment

              Working...