Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.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# Properties.Settings.Default.variableName=textboxt.Text_C#_Winforms - Fatal编程技术网

C# Properties.Settings.Default.variableName=textboxt.Text

C# Properties.Settings.Default.variableName=textboxt.Text,c#,winforms,C#,Winforms,基本上,我试图获取一个带有一些文件路径的文本框,检查它是否存在,如果存在,将Properties.Settings.Default.system的值设置为temp.text 但是,我不知道如何使用变量名来引用现有的设置属性 这是一个全新的概念,因此我们非常感谢您的帮助 谢谢 答案要归功于迈克·德贝拉。。。。但是,如果遇到您不了解系统的情况,此代码将有助于防止出现一些错误 private void Enable(TextBox temp, String system) {

基本上,我试图获取一个带有一些文件路径的文本框,检查它是否存在,如果存在,将Properties.Settings.Default.system的值设置为temp.text

但是,我不知道如何使用变量名来引用现有的设置属性

这是一个全新的概念,因此我们非常感谢您的帮助


谢谢

答案要归功于迈克·德贝拉。。。。但是,如果遇到您不了解系统的情况,此代码将有助于防止出现一些错误

    private void Enable(TextBox temp, String system)
    {

        if (File.Exists(temp.Text))
        {
            Properties.Settings.Default.system = temp.Text;
        }
        else
            do something here;
    }
private void启用(文本框临时,字符串系统)
{
//检查该属性是否存在
bool propertyExists=Properties.Settings.Default.Properties.Cast().Any(p=>p.Name==system);
如果(不动产存在)
{
Properties.Settings.Default[系统]=临时文本;
}
其他的
{
//创建一个新属性
var p=新设置属性(系统);
p、 PropertyType=typeof(字符串);
p、 DefaultValue=临时文本;
Properties.Settings.Default.Properties.Add(p);
}
Properties.Settings.Default.Save();
}

答案要归功于迈克·德贝拉。。。。但是,如果遇到您不了解系统的情况,此代码将有助于防止出现一些错误

    private void Enable(TextBox temp, String system)
    {

        if (File.Exists(temp.Text))
        {
            Properties.Settings.Default.system = temp.Text;
        }
        else
            do something here;
    }
private void启用(文本框临时,字符串系统)
{
//检查该属性是否存在
bool propertyExists=Properties.Settings.Default.Properties.Cast().Any(p=>p.Name==system);
如果(不动产存在)
{
Properties.Settings.Default[系统]=临时文本;
}
其他的
{
//创建一个新属性
var p=新设置属性(系统);
p、 PropertyType=typeof(字符串);
p、 DefaultValue=临时文本;
Properties.Settings.Default.Properties.Add(p);
}
Properties.Settings.Default.Save();
}

你是说像这样<代码>属性.设置.默认值[“系统”]Awesome!非常感谢你。做了我想要的,你是说这样<代码>属性.设置.默认值[“系统”]Awesome!非常感谢你。做了我需要的。目前只是手动传递变量,没有输入。尽管谢谢你的建议,我的程序可能会发展到我需要的地方。目前只是手动传递变量,没有输入。尽管谢谢你的建议,我的程序可能会发展到我需要的地方。