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

Converting string array to int array c#

Discussion in 'Scripting' started by Thomas the Hun, Feb 25, 2015.

  1. Thomas the Hun

    Thomas the Hun

    Joined:
    Feb 25, 2015
    Posts:
    2
    Hi!

    I'm trying to convert a string array into an int array. I previously did it in VB to test it, and worked fine there, but it doesn't work in Unity.

    I got the following:

    Code (CSharp):
    1. string[] mystring = new string[]  { "123","248","168"};
    2. int[] myint = new int[3];
    3.  
    4. //This worked in VB:
    5. myint = Array.ConvertAll(mystring, int.Parse);
    6.  
    7. //The only way I could get it to work in Unity was:
    8. for (i=0;i<4;i++)
    9. {
    10. myint[i] = int.Parse(mystring[i]);
    11. }
    Any idea where I went wrong?
    Thanks!
     
  2. Deleted User

    Deleted User

    Guest

    The .NET version of that function is not supported. You can use myInt.ToString()
     
  3. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    You forgot the types '<string, int>':
    Code (CSharp):
    1. myint = Array.ConvertAll<string, int>(mystring, int.Parse);
     
    imDanOush and christougher like this.
  4. Thomas the Hun

    Thomas the Hun

    Joined:
    Feb 25, 2015
    Posts:
    2
    Thanks, now it works fine!