بسيطة 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 */
نصائح أخرى
يجب أن يكون استخدام مايكروسوفت.Win32.التسجيل فئة.و ذات فصول ، كل ما تحتاجه للعمل مع سجل ويندوز.
لا تنتمي إلى StackOverflow