具有 Getters 和 Setters 的简单 C# 注册表对象
我如何在 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;
}
}
}
}
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;
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需向您的注册表类添加一个属性:
然后像这样使用:
Simply add a property to your Registry class:
Then use like this:
您应该使用 Microsoft.Win32.Registry班级。它和相关的类具有使用 Windows 注册表所需的一切。
You should be using the Microsoft.Win32.Registry class. It, and the related classes, have all you need to work with the Windows registry.