gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 19:40:25 27 4
gpt4 key购买 nike

通过 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com