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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Array.Sort CS0103: The name `Array' does not exist in the current context

Discussion in 'Scripting' started by KronosIII, May 12, 2018.

  1. KronosIII

    KronosIII

    Joined:
    May 11, 2018
    Posts:
    6
    Hi, I'm a beginner, I'm learning C# directly in Unity. :)

    I have a problem, the method Array.Sort doesn't work for my list. I'm sure it's stupid. ^^

    CS0103: The name `Array' does not exist in the current context

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Tableau : MonoBehaviour {
    6.  
    7.     // Use this for initialization
    8.     void Start () {
    9.         string[] jours = new string[] {"Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche" };
    10.         //Debug.Log(jours[2]);
    11.  
    12.         Array.Sort (jours);
    13.         Debug.Log("Ordre Alphabetique");
    14.  
    15.         foreach (string c in jours) {
    16.             Debug.Log(c);
    17.         }
    18.        
    19.     }
    20.    
    21.     // Update is called once per frame
    22.     void Update () {
    23.        
    24.     }
    25. }
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,186
    Code (csharp):
    1. using System;
     
  3. KronosIII

    KronosIII

    Joined:
    May 11, 2018
    Posts:
    6
    Thank you very much it's working. ^^

    Is it because there aren't all method?
     
  4. realm01

    realm01

    Joined:
    Sep 23, 2016
    Posts:
    2
    System
    is a namespace (see: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/namespaces/using-namespaces)
    using System;
    tells the compiler that you want to access this namespace in that file.
    Array
    is a class in the
    System
    namespace. (See: https://docs.microsoft.com/en-us/dotnet/api/system.array) And
    Sort
    is a static method within the
    Array
    class. (See: https://docs.microsoft.com/en-us/dotnet/api/system.array.sort)
     
    KronosIII likes this.
  5. KronosIII

    KronosIII

    Joined:
    May 11, 2018
    Posts:
    6
    Ok, I understand thanks for the links it's very helpful.