Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 创建设置的新实例_C#_Constructor_Settings - Fatal编程技术网

C# 创建设置的新实例

C# 创建设置的新实例,c#,constructor,settings,C#,Constructor,Settings,我将编写一个振动分析程序,类似于一个学校项目,它将使用传感器测量振动和其他一些东西,然后使用一些算法进行分析 无论如何,我希望用户能够设置参数和变量,因此创建了一些不同的设置集。不过,问题是,由于我将有许多相同类型的传感器(我不知道现在有多少个),因此在添加传感器时,我希望创建这些设置的新集合或实例。此外,还有一些变量类型,我不知道会有多少这种类型的实例(比如说不同的RPM来比较振动),因此我希望能够添加该变量的另一个实例 有人知道应该如何做到这一点吗?这可能很简单,但谷歌什么也没给我,试图用构

我将编写一个振动分析程序,类似于一个学校项目,它将使用传感器测量振动和其他一些东西,然后使用一些算法进行分析

无论如何,我希望用户能够设置参数和变量,因此创建了一些不同的设置集。不过,问题是,由于我将有许多相同类型的传感器(我不知道现在有多少个),因此在添加传感器时,我希望创建这些设置的新集合或实例。此外,还有一些变量类型,我不知道会有多少这种类型的实例(比如说不同的RPM来比较振动),因此我希望能够添加该变量的另一个实例

有人知道应该如何做到这一点吗?这可能很简单,但谷歌什么也没给我,试图用构造函数创建一个新实例根本不起作用

这就是我迄今为止所尝试的:

    AccelerometerSettings Sensor3 = new AccelerometerSettings(); 
给了我一个名为Sensor3的加速计设置的新实例,但是

    Sensor3.accelerometerResolution = 10; 
(我在双精度加速度计设置中有一个设置,称为分辨率)没有给我任何信息。或者实际上,它给了我一个“=”错误,并说这是一个无效的令牌,accelerometerResolution是一个字段,但用作类型

编辑:以下是Visual Studio自动生成的设置类的代码:

        //------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.18052
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Fault_detection_system {


    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
    internal sealed partial class AccelerometerSettings : global::System.Configuration.ApplicationSettingsBase {

        private static AccelerometerSettings defaultInstance = ((AccelerometerSettings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new AccelerometerSettings())));

        public static AccelerometerSettings Default {
            get {
                return defaultInstance;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("Accelerometer-Name")]
        public string accelerometerName {
            get {
                return ((string)(this["accelerometerName"]));
            }
            set {
                this["accelerometerName"] = value;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("20.0")]
        public decimal accelerometerResolution {
            get {
                return ((decimal)(this["accelerometerResolution"]));
            }
            set {
                this["accelerometerResolution"] = value;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("10.0")]
        public decimal accelerometerAccuracyUp {
            get {
                return ((decimal)(this["accelerometerAccuracyUp"]));
            }
            set {
                this["accelerometerAccuracyUp"] = value;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("10.0")]
        public decimal accelerometerAccuracyDown {
            get {
                return ((decimal)(this["accelerometerAccuracyDown"]));
            }
            set {
                this["accelerometerAccuracyDown"] = value;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("10")]
        public decimal faultFrequency {
            get {
                return ((decimal)(this["faultFrequency"]));
            }
            set {
                this["faultFrequency"] = value;
            }
        }
    }
//------------------------------------------------------------------------------
// 
//这段代码是由一个工具生成的。
//运行时版本:4.0.30319.18052
//
//对此文件的更改可能会导致不正确的行为,如果
//重新生成代码。
// 
//------------------------------------------------------------------------------
名称空间故障检测系统{
[全局::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(“Microsoft.VisualStudio.Editor.SettingsDesigner.SettingsSingleFileGenerator”,“11.0.0.0”)]
内部密封部分类加速计设置:全局::System.Configuration.ApplicationSettingsBase{
私有静态AccelerometerSettings defaultInstance=((AccelerometerSettings)(全局::System.Configuration.ApplicationSettingsBase.Synchronized(新AccelerometerSettings()));
公共静态加速度计默认设置{
得到{
返回默认实例;
}
}
[全局::System.Configuration.UserScopedSettingAttribute()]
[全局::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute(“加速计名称”)]
公共字符串加速计名称{
得到{
返回((字符串)(此[“accelerometerName]”);
}
设置{
此[“accelerometerName”]=值;
}
}
[全局::System.Configuration.UserScopedSettingAttribute()]
[全局::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute(“20.0”)]
公共十进制加速度计解决方案{
得到{
返回((十进制)(此[“accelerometerResolution”]);
}
设置{
此[“加速度计溶液”]=数值;
}
}
[全局::System.Configuration.UserScopedSettingAttribute()]
[全局::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute(“10.0”)]
公共十进制加速度计准确度{
得到{
返回((十进制)(此[“accelerometerAccuracyUp”]);
}
设置{
此[“AccelerometraccuracyUp”]=值;
}
}
[全局::System.Configuration.UserScopedSettingAttribute()]
[全局::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute(“10.0”)]
公共十进制加速度计精度下降{
得到{
返回((十进制)(此[“AccelerometraccuracyDown”]);
}
设置{
此[“AccelerometraccuracyDown”]=值;
}
}
[全局::System.Configuration.UserScopedSettingAttribute()]
[全局::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute(“10”)]
公共频率{
得到{
返回((十进制)(此[“故障频率]));
}
设置{
此[“故障频率”]=值;
}
}
}
这是您的类,您可以在运行时通过静态属性
Default
访问该类,该属性允许您从app.config文件中访问加载的设置,该文件类型为
AccelerometerSettings
,您可以访问其属性,如下所示:

var resolution = AccelerometerSettings.Default.accelerometerResolution;
如果要更改设置并将其保存在user.config中

 AccelerometerSettings.Default.accelerometerResolution = 42.0;
 AccelerometerSettings.Default.Save();

现在你已经告诉了我们你想要什么,告诉我们你尝试了什么…(发布你的代码)。我已经编辑了你的标题。请看,“,其中的共识是“不,他们不应该”@user2950764-不要在评论中发布你的代码。请编辑你的帖子并将其添加到那里。谢谢提醒,我下次会考虑这个问题!@Brian:我没想到我可以像在评论中那样发布超过5分钟的帖子,但我现在已经完成了。为AccelerometerSettings类发布代码。