Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to convert INT to ULONG using Unity C# ?

Discussion in 'Scripting' started by AlanMattano, Jul 5, 2015.

  1. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,500
    My code
    Code (CSharp):
    1. ulong delay = (int) frequency;
    Gives an error:
    Cannot implicitly convert type `int' to `ulong'. An explicit conversion exists (are you missing a cast?)

    How can i make this explicit conversion or where to find it?

    Can be:
    Code (CSharp):
    1. ulong delay = Convert.ToUInt64(frequency);
    But needs extra code?

    Thx.
     
    Last edited: Jul 5, 2015
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,397
    Code (csharp):
    1. ulong delay = (ulong) frequency;
    The part in () is what you are converting to, not converting from. The compiler already knows what type "frequency" is; you need to tell it what type you want to convert to (since it doesn't know that part).

    --Eric
     
  3. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,500
    :rolleyes::D I'm still laughing

    Thx Eric !
     
    Last edited: Jul 5, 2015