WinForms C#-静态字符串 [英] WinForms C# - Static Strings

查看:68
本文介绍了WinForms C#-静态字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,所以我有2个表单,Form1和&表格2.我也有一个要在其中存储变量的类.

我正在尝试在我的Variables.cs中将静态字符串设置为与Form1中的标签具有相同的文本.

        private void IDD_EDIT_1_Click(object sender, EventArgs e)
        {
            Connection_Variables vars = new Connection_Variables();
            vars.connectionName = IDD_DATA_LABLE_1.Text;
            OpenEditorConnection();
        }

这是来自Form1的代码,用于尝试设置静态字符串,但出现错误:

Member 'Connection_Variables.connectionName' cannot be accessed with an instance reference; qualify it with a type name instead

这是我的整个Connection_Variables类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MySQLConnectionTest
{
    public class Connection_Variables
    {
        public static string connectionName;
    }
}

通过单击按钮,我希望它设置为 静态字符串 connectionName " 文本作为标签 .

By clicking the button I want it to set that Static String "connectionName" to the same as the Text as the label.

希望我对此解释得足够好,感谢您的阅读和帮助!

斯科特

推荐答案

您尝试过吗?

Connection_Variables.connectionName = IDD_DATA_LABLE_1.Text;

否则请删除静态".

公共字符串connectionName;

-韦恩

Have you tried this?

Connection_Variables.connectionName = IDD_DATA_LABLE_1.Text;

Or else remove the "static".

public string connectionName;

- Wayne


这篇关于WinForms C#-静态字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆