Tag: static variables

C#在实例化时递增静态变量

我有一个bankAccount对象,我想使用构造函数递增。 目标是让它与类实例化的每个新对象一起递增。 注意:我重写了ToString()以显示accountType和accountNumber; 这是我的代码: public class SavingsAccount { private static int accountNumber = 1000; private bool active; private decimal balance; public SavingsAccount(bool active, decimal balance, string accountType) { accountNumber++; this.active = active; this.balance = balance; this.accountType = accountType; } } 为什么当我将其插入主体时如此: class Program { static void Main(string[] args) { SavingsAccount potato = new SavingsAccount(true, 100.0m, […]

C#中的静态变量

在C#中,有没有办法将静态变量放在像VB.Net这样的方法中? Static myCollection As Collection