0

I have the following class that is used in conjunction with the data object for PropertyGrid:

public enum WebUILanguage
{
    EnglishUS,
    German,
    //Actual list is obviously longer
}

[DefaultPropertyAttribute("SaveOnClose")]
public class MyData
{
    private HashSet<WebUILanguage> _SupportedUILanguages = new HashSet<WebUILanguage>(_k_SupportedUILanguages);

    //Area to define all default values    
    const WebUILanguage[] _k_SupportedUILanguages = {   //Error CS0134: A const field of a reference type other than string can only be initialized with null.
        WebUILanguage.EnglishUS,
        WebUILanguage.German
    };

    [CategoryAttribute("User Interface"),
    DefaultValueAttribute(_k_SupportedUILanguages),
    DescriptionAttribute("Supported user interface languages.")]
    [RefreshProperties(RefreshProperties.All)]
    public WebUILanguage[] SupportedUILanguages
    {
        get { return _SupportedUILanguages.ToArray(); }
        set 
        { 
            //Do 'set' magic here
        }
    }
}

But the compiler doesn't let me initialize a constant array -- the _k_SupportedUILanguages constant in the code above. What is the syntax for that?

PS. Note that I do not need a readonly array. It must be const!

c00000fd
  • 20,994
  • 29
  • 177
  • 400

0 Answers0