Results 1 to 5 of 5

Thread: [RESOLVED] long? CompareTo

  1. #1

    Thread Starter
    Hyperactive Member Greyskull's Avatar
    Join Date
    Dec 2003
    Location
    somewhere in England
    Posts
    382

    Resolved [RESOLVED] long? CompareTo

    the type 'long' has a 'compareto()' method but how would you do it if the variable is type 'long?' ?

    Basically got a class that contains a variable called FileSize which contains null if it is a folder and other files should have a value for it..so for sorting the specific field, I will need to do a 'compareTo()' but don't seem to do it.

    Any ideas? Thanks
    Please go to the Thread Tools menu and click Mark Thread Resolved when your post is answered
    If someone helped you today then please consider rating their post.

  2. #2
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: long? CompareTo

    nullable<long> has a Compare method if it's any help.

    You can also specify your own comparison methods.
    W o t . S i g

  3. #3

    Thread Starter
    Hyperactive Member Greyskull's Avatar
    Join Date
    Dec 2003
    Location
    somewhere in England
    Posts
    382

    Re: long? CompareTo

    Thanks for the reply..

    am I doing something wrong with this code then?

    Code:
    Nullable.Compare<FileSystemItem>(item1.Size, item2.Size);
    Please go to the Thread Tools menu and click Mark Thread Resolved when your post is answered
    If someone helped you today then please consider rating their post.

  4. #4
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: long? CompareTo

    Are you comparing nullable FileSystemItems or nullable longs?

    Code:
    int comp = Nullable.Compare<long>(item1.Size, item2.Size);
    //or
    int comp = Nullable.Compare(item1.Size, item2.Size);
    W o t . S i g

  5. #5

    Thread Starter
    Hyperactive Member Greyskull's Avatar
    Join Date
    Dec 2003
    Location
    somewhere in England
    Posts
    382

    Re: long? CompareTo

    The latter line of code worked wonders.

    Thanks very much ^_^
    Please go to the Thread Tools menu and click Mark Thread Resolved when your post is answered
    If someone helped you today then please consider rating their post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width