quot;Objectquot; does not contain a definition for quot;namequot;(“对象不包含“名称的定义;)
问题描述
我收到一条错误消息,告诉我:
I'm having an error message that tells me this:
BankAccount.account"不包含提款"的定义.
'BankAccount.account' does not contain a definition for 'withdraw'.
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BankAccounts
{
class account
{
protected string name;
protected float balance;
public account(string n, float b)
{
name = n;
balance = b;
}
public void deposit(float amt)
{
balance -= amt;
}
public void display()
{
Console.WriteLine("Name: {0}. Balance: {1}.", name, balance);
}
}
class savingaccount : account
{
static int accno = 1000;
int trans;
public savingaccount(string s, float b) : base(s, b)
{
trans = 0;
accno++;
}
public void withdraw (float amt)
{
if (trans >= 10)
{
Console.WriteLine("Number of transactions exceed 10.");
return;
}
if (balance - amt < 500)
Console.WriteLine("Below minimum balance.");
else
{
base.withdraw(amt);
trans++;
}
}
public void deposit(float amt)
{
if (trans >= 10)
{
Console.WriteLine("Number of transactions exceed 10.");
return;
}
base.deposit(amt);
trans++;
}
public void display()
{
Console.WriteLine("Name: {0}. Account no.: {1}. Balance: {2}", name, accno, balance);
}
}
class currentaccount : account
{
static int accno = 1000;
public currentaccount(string s, float b) : base(s, b)
{
accno++;
}
public void withdraw(float amt)
{
if (balance - amt < 0)
Console.WriteLine("No balance in account.");
else
balance -= amt;
}
public void display()
{
Console.WriteLine("Name: {0}. Account no.: {1}. Balance: {2}.", name, accno, balance);
}
}
}
我不明白为什么它不识别它.它是类 Savingaccount 中的一个方法.
I don't understand why it doesn't recognize it. It is a method in the class savingaccount.
推荐答案
你来电
base.withdraw(amt);
来自您的班级savingsaccount
.但是基类(account
)没有这样的方法.所以编译器是绝对正确的.
from your class savingsaccount
. But the base class (account
) has no such method. So the compiler is absolutely correct.
这篇关于“对象"不包含“名称"的定义;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“对象"不包含“名称"的定义;
基础教程推荐
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01