c# - 元组必须包含至少两个元素

标签 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://learn.microsoft.com/en-us/dotnet/csharp/tutorials/intro-to-csharp/introduction-to-classes

感谢对我的困境的任何见解。

最佳答案

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

示例:

using System;

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

关于c# - 元组必须包含至少两个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54244287/

相关文章:

c# - 企业图书馆的优缺点

c# - 在 Controller 中提交时 ViewModel 值为空

c# - AppSettings 清除 app.config 中的 Xml 元素

c# - 在 C# 中使用使用 COM 的 DLL

c# - 您如何测试软件发布版本之间的代码性能?

c# - 面试代码示例

c# - FileStream 构造函数和默认缓冲区大小

c# - 使用 StringFormat 转换为字符串

.net - 依赖注入(inject)启动性能

c# - 谁能解释 VDPROJ 文件的主要特征?