0

C#でこのようなことをどのように達成しますか?

object Registry;
Registry = MyProj.Registry.Instance;

int Value;
Value = 15;
Registry.Value = Value; /* Sets it to 15 */
Value = 25;
Value = Registry.Value; /* Returns the 15 */

これまでのところ、私はこのオブジェクトを持っています:

namespace MyProj
{
    internal sealed class Registry
    {
        static readonly Registry instance = new Registry();

        static Registry()
        {
        }

        Registry()
        {
        }

        public static Registry Instance
        {
            get
            {
                return instance;
            }
        }
    }
}
4

2 に答える 2

4

レジストリクラスにプロパティを追加するだけです。

internal sealed class Registry
{
    public int Value { get; set; }
    ...
}

次に、次のように使用します。

Registry theRegistry = MyProj.Registry.Instance;
//note: do not use object as in your question

int value = 15;
theRegistry.Value = value; /* Sets it to 15 */
value = 25;
value = theRegistry.Value; /* Returns the 15 */
于 2009-10-08T11:33:55.063 に答える
2

Microsoft.Win32.Registryクラスを使用する必要があります。それと関連するクラスには、Windowsレジストリを操作するために必要なものがすべて揃っています。

于 2009-10-08T11:33:48.317 に答える