Simple C# registry object with Getters and Setters
Question
How would I achieve something like this 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 */
So far I have this object:
namespace MyProj
{
internal sealed class Registry
{
static readonly Registry instance = new Registry();
static Registry()
{
}
Registry()
{
}
public static Registry Instance
{
get
{
return instance;
}
}
}
}
Solution
Simply add a property to your Registry class:
internal sealed class Registry
{
public int Value { get; set; }
...
}
Then use like this:
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 */
OTHER TIPS
You should be using the Microsoft.Win32.Registry class. It, and the related classes, have all you need to work with the Windows registry.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow