0

我有以下与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
        }
    }
}

但是编译器不允许我初始化一个常量数组——_k_SupportedUILanguages上面代码中的常量。它的语法是什么?

PS。请注意,我不需要数组readonly。它必须是常量!

4

0 回答 0