나는 변수가있는 PublicSettings.cs
이라는 파일 (이 파일은 Class라는 폴더 안에 있습니다)과 함께 C# winforms에 프로젝트를 가지고 있습니다.다른 파일의 변수를 사용합니다 .cs
이제 동일한 프로젝트 내의 다른 파일에서 해당 변수를 사용하고 싶습니다.
PublicSettings.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LVSetup.Class
{
class PublicSettings
{
private string _ConnStr = "Connection";
public string ConnStr
{
get
{
return this._ConnStr;
}
set
{
this._ConnStr = value;
}
}
}
}
내가 파일에 변수 ConnStr
를 사용하려면 : frmLogin.cs
frmLogin.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LVSetup.Class;
namespace LVSetup
{
public partial class frmLogin : Form
{
public frmLogin()
{
InitializeComponent();
}
private void btnEnter_Click(object sender, EventArgs e)
{
string a = PublicSettings.ConnStr;
}
}
}
그러나 더 ConnStr
내 없다 PublicSettings
, 그냥 (동등 및 참조 동등 물)
무엇이 잘못 될 수 있습니까?
정적 컨텍스트에서 정적 변수가 아닌 변수에 액세스하려고합니다. – DairyLea
이 질문은 핵심적인 C# 구문에 관한 것이므로 문서 및 자습서를주의 깊게 읽어 보면 쉽게 해결할 수 있습니다. . – walther
@walther, 그게 위대한 downvote 이유. 그다지 가까운 이유는. – paqogomez