# Semplice oggetto C registro con getter e setter
Domanda
Come faccio a ottenere qualcosa di simile in 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 */
Finora ho questo oggetto:
namespace MyProj
{
internal sealed class Registry
{
static readonly Registry instance = new Registry();
static Registry()
{
}
Registry()
{
}
public static Registry Instance
{
get
{
return instance;
}
}
}
}
Soluzione
È sufficiente aggiungere una proprietà alla classe Registry:
internal sealed class Registry
{
public int Value { get; set; }
...
}
Quindi utilizzare in questo modo:
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 */
Altri suggerimenti
Si dovrebbe essere utilizzando il Microsoft.Win32.Registry di classe. E ', e le relative classi, hanno tutto ciò che serve per lavorare con il registro di Windows.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow