質問

どのように私は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;
            }
        }
    }
}
役に立ちましたか?

解決

単にあなたのレジストリクラスにプロパティを追加します:

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 */
scroll top