Pergunta

Como eu conseguiria algo assim em 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 */

Até agora eu tenho esse objeto:

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

        static Registry()
        {
        }

        Registry()
        {
        }

        public static Registry Instance
        {
            get
            {
                return instance;
            }
        }
    }
}
Foi útil?

Solução

Basta adicionar uma propriedade à sua aula de registro:

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

Em seguida, use assim:

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

Outras dicas

Você deveria estar usando o Microsoft.win32.registry classe. Ele e as classes relacionadas têm tudo o que você precisa para trabalhar com o registro do Windows.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top