C#制作字符串公开? [英] C# making string public?

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

问题描述

您好我有一个非常愚蠢的问题

但是无论如何都要问:)


$ form $ formboad事件我有这个



string datacompany = rm.GetString(datacompany);



我稍后在formLoad中使用此datacompany,但是我也必须在buttonClick事件上使用这个datacompany,我不想再做这个字符串但是想调用datacompany,

愚蠢的问题,是怎么做的:(我知道真的很蠢

Hello I have a really stupid question
but gonna ask anyway :)

on formLoad event I have this

string datacompany = rm.GetString("datacompany");

and I use this datacompany later on in formLoad, but I have to use this datacompany on buttonClick event also, and I dont want to make this string again but want to call datacompany,
Stupid question, is how to do this :( I know really stupid

推荐答案

您需要使用属性 [ ^ ]。



You need to use properties[^].

private string datacompany;
public string DataCompany{
  set{
    datacompany = value;
  }
  get{
    return datacompany;
  }
}





然后致电



then call

DataCompany = rm.GetString("datacompany");





希望这有帮助。



hope this helps.


将其声明为表单类的成员(而不是formLoad的本地)方法)。

如果您在表单类中使用它,那么您不需要将其声明为 public



Declare it as member of the form class (instead of local of the formLoad method).
If you are using it in the form class itself then you don''t need to declare it as public.

public partial class MyForm : Form
{
  string datacompany;
   //...










private void MyForm_Load(object sender, EventArgs e)
{
  datacompany = rm.GetString("datacompany");
  //..

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

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