getters and 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;
}
}
}
}
해결책
레지스트리 클래스에 속성을 추가하기 만하면됩니다.
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 */
다른 팁
당신은 그것을 사용해야합니다 Microsoft.win32.registry 수업. IT 및 관련 클래스는 Windows 레지스트리에서 작업하는 데 필요한 모든 것을 갖추고 있습니다.
제휴하지 않습니다 StackOverflow