How to make a static read-only array?

I can’t add const to an array and readonly is not preventing the array from being edited.

 public const string OceanMenu = "OceanMenu";
 public const string IslandMenu = "IslandMenu";
public static readonly string[]  MenuScenes = new string[] {OceanMenu, IslandMenu,};
        DefaultSceneNames.MenuScenes[1] = "override";

        for (int i = 0; i < 20; i++)
        {
            int randomIndex = Random.Range(0, DefaultSceneNames.MenuScenes.Length);

            Debug.Log(DefaultSceneNames.MenuScenes[randomIndex]);
        }

The readonly modifier obviously only affects the variable, not the array object behind the variable. I personally don’t bother when coding games cos of the general tongue-in-the-cheekness, but you can use ReadOnlyCollection<T> class if you need this.

Alternatively you can cast the array to IReadOnlyList<string>.

public static readonly IReadOnlyList<string> MenuScenes = new string[] {OceanMenu, IslandMenu,};

It’s the kind of thing you can obfuscate behind an enumerator:

public const string OceanMenu = "OceanMenu";
public const string IslandMenu = "IslandMenu";

private static string[] menuScenes = new string[] { OceanMenu, IslandMenu };

public static IEnumerable<string> EnumerateMenuScenes()
{
    int sceneCount = menuScenes.Length;
    int (i = 0; i < sceneCount; i++)
    {
        yield return menuScenes[i];
    }
}

Your IReadOnlyList works, but I forgot that simply making the array private can prevent it from being edited by other classes.

 private static string[] MenuScenes = new string[] {OceanMenu, IslandMenu};

    public static string GetRandomMenuScene()
    {
        return MenuScenes[Random.Range(0, MenuScenes.Length)];
    }