我正在尝试研究 c# 中的嵌套类。在阅读了许多文档和凝视之后,我仍然不清楚何时使用嵌套类。但据我了解,我做了一个小示例程序。我在下面粘贴我的代码。这个嵌套类程序是否以正确的逻辑实现?. 嵌套类实际上使用的是什么 for ?而且我对这个程序有疑问,我在程序中指定了这个疑问。请帮我 ...
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Bank bankObj = new Bank();
bankObj.CreateAccount();
bankObj.ShowMyAccountNumber();
}
}
class Bank
{
static int accountNumber; // here if I just declare this as int accountNumber without static it showing an error in the CreatePersonalAccount(int accNo) method's first line ie accountNumber = accNo; as "Cannot access a non-static member of outer type." What actually this error mean ?
public class BankAccountSection
{
public bool CreatePersonalAccount(int accNo)
{
accountNumber = accNo;
return true;
}
}
public void CreateAccount()
{
bool result = new BankAccountSection().CreatePersonalAccount(10001);
}
public void ShowMyAccountNumber()
{
MessageBox.Show(accountNumber.ToString());
}
}