이 과제에서 나는 BankAccount 프로그램으로 몇 가지 작업을 수행해야하지만, 먼저 예제를 실행시켜야합니다. 아래의 스크린 샷과 같이 과제 시트의 코드를 복사했지만 아래에 오류가 표시됩니다.이중에서 소수점 이하의 오류로 변환 할 수 없음
Error 2 Argument 1: cannot convert from 'double' to 'decimal' Line 13 Column 51
Error 1 The best overloaded method match for 'BankAccount.BankAccount.BankAccount(decimal)' has some invalid arguments Line 13 Column 35
Error 4 Argument 1: cannot convert from 'double' to 'decimal' Line 13 Column 30
Error 3 The best overloaded method match for 'BankAccount.BankAccount.Withdraw(decimal)' has some invalid arguments Line 18 Column 13
나는 내가 한 번 두 번 사용했습니다 생각하지 않으며, 오류의 매우 빠른 구글이 나에게 도움이되지 않았다 이러한 오류의 원인 무엇인지 전혀 모른다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BankAccount
{
class Program
{
static void Main(string[] args)
{
// Create Bank Account & Print Balance
BankAccount account = new BankAccount(142.50);
Console.WriteLine("Account Balance is: " + account.ToString());
// Withdraw £30.25
Console.WriteLine("Withdrawing £30.25");
account.Withdraw(30.25);
// Print balance again
Console.WriteLine("Account Balance is: " + account.ToString());
}
}
. 여기
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BankAccount
{
public class BankAccount
{
private decimal _balance;
public decimal Balance
{
get { return _balance; }
private set { _balance = value; }
}
//Constructor: Constructs a new Bank Account with 0 balance
public BankAccount()
{
Balance = 0;
}
//Constructor: Constructs a new Bank Account with the specified balance
public BankAccount(decimal balance)
{
Balance = balance;
}
//Deposits the specified amount into the Bank Account
public void Deposit(decimal amount)
{
Balance += amount;
}
//Withdraws the specified amount from the Bank Account
public void Withdraw(decimal amount)
{
Balance -= amount;
}
//ToString Override
public override string ToString()
{
return string.Format("{0}: Balance = {1}", "BankAccount", Balance);
}
}
}
사진 대신에 질문의 본문에 코드를 게시하십시오. 또한 코드에서 오류가 발생한 위치를 알려줌으로써 상황이 어디에서 발생하는지 파악할 필요가 없습니다. –
소수점 리터럴은'm' 접미사로 표시되므로 생성자에'decimal' 인수가 필요한 경우'new BankAccount (142.50m) '을 사용해야합니다. – Lee
나는 캐스트가없는 십진수로 전달하려고하는 double을 반환하는 함수를 가지고있을 것입니다. 즉, 내 작업 블록 이후로 코드를 볼 수 없습니다. – IllusiveBrian