元组必须包含至少两个元素

时间:2019-01-17 21:05:54

标签: c# .net

浏览Microsoft文档并完成教程,我目前正在研究“类和对象”模块。

using System;

namespace classes
{
public class BankAccount
{
    public string Number { get; }
    public string Owner { get; set; }
    public decimal Balance { get; }
    public BankAccount(string name, decimal initialBalance)
    {
      this.Owner = name;
      this.Balance = initialBalance;
    }

    public void MakeDeposit(decimal amount, DateTime date, string note)
    {
    }

    public void MakeWithdrawal(decimal amount, DateTime date, string note)
    {
    }
}

}

是我们的开始,我将在Program.cs文件中调用此类作为测试

using System;

namespace classes
{
    public class Program
    {
        var account = new BankAccount("<HAMID>", 1000);
        Console.WriteLine($"Account {account.Number} was created for {account.Owner} with {account.Balance} initial balance.");

    }
}

但是我在Console.WriteLine(“ ...”)

中收到此错误

"Type expected , tuple must be at least two elements, ) expected, invalid token $"Account {account.Number} was created for {account.Owner} with {account.Balance} initial balance."

我要浏览的文章的链接是

https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/intro-to-csharp/introduction-to-classes

赞赏关于我的困境的任何见识。

1 个答案:

答案 0 :(得分:6)

您在static void Main(string[] args)类中缺少Program方法。

示例:

using System;

namespace classes
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}