簡體   English   中英

具有Getter和Setter的簡單C#注冊表對象

[英]Simple C# registry object with Getters and Setters

我如何在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;
            }
        }
    }
}

只需將一個屬性添加到您的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 */

您應該使用Microsoft.Win32.Registry類。 它和相關類具有處理Windows注冊表所需的全部。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM