标签: static-indexers

静态索引器?

为什么C#中不允许使用静态索引器?我认为没有理由不允许他们这样做,而且他们可能非常有用.

例如:

public static class ConfigurationManager 
{
        public object this[string name]
        {
            get => ConfigurationManager.getProperty(name);
            set => ConfigurationManager.editProperty(name, value);
        }

        /// <summary>
        /// This will write the value to the property. Will overwrite if the property is already there
        /// </summary>
        /// <param name="name">Name of the property</param>
        /// <param name="value">Value to be wrote (calls ToString)</param>
        public static void editProperty(string name, object value) 
        {
            var ds = new DataSet();
            var configFile = new FileStream("./config.xml", FileMode.OpenOrCreate);
            ds.ReadXml(configFile);

            if (ds.Tables["config"] == null)
                ds.Tables.Add("config"); …
Run Code Online (Sandbox Code Playgroud)

.net c# static indexer static-indexers

114
推荐指数
3
解决办法
4万
查看次数

标签 统计

.net ×1

c# ×1

indexer ×1

static ×1

static-indexers ×1