我如何在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;
}
}
}
}
答案 0 :(得分:4)
只需在Registry类中添加一个属性:
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 */
答案 1 :(得分:2)
您应该使用Microsoft.Win32.Registry课程。它以及相关的类具有使用Windows注册表所需的一切。