Console.writeline不起作用, [英] Console.writeline is not working,

查看:533
本文介绍了Console.writeline不起作用,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;

命名空间 Lab4
{
class 计划
{
静态 void Main( string [] args)

{
SavingAccount aSavingAccount;
列表< savingaccount> accounts = new 列表< savingaccount>();
while true
{
Console.Write(< span class =code-string> 请输入帐户所有者的名称:);
string Owner = Console.ReadLine();

if (所有者==
break ;

Console.Write( 请输入储蓄账户的初始存款金额: );
string entry1 = Console.ReadLine();
double InitialDepositAmount = double .Parse(entry1);

Console.Write( 请输入储蓄账户的每月存款金额:< /跨度>);
string entry2 = Console.ReadLine();
double MonthlyDepositAmount = double .Parse(entry2);

aSavingAccount = new SavingAccount(Owner,InitialDepositAmount);
aSavingAccount.MonthlyDepositAmount = MonthlyDepositAmount;

accounts.Add(aSavingAccount);

}

foreach (SavingAccount account in accounts)
{
for int i = 0 ; i < 6 ; i ++)
{
account.Withdraw(SavingAccount.MonthlyFee);
account.Deposit(account.MonthlyDepositAmount);
account.Deposit(SavingAccount.MonthlyInterestRate * account.Balance);
}
Console.WriteLine( 6个月后,{0}的帐户(# {1}),余额为:{2:C},account.Owner,account.AccountNumber,account.Balance);
}

}
}





我尝试过:



我试图在visual studio的另一个窗口中运行,但它显示全行代码的所有红线错误

解决方案

首先,C#区分大小写,所以

 SavingAccount aSavingAccount; 

与<$不同的类p $ p>列表与LT; savingaccount> accounts = new List< savingaccount>();

由于它们是不同的类,后者不能包含前者的实例!另外,一个可能是错的,所以编译器可能会告诉你我找不到类XXX。



红线告诉有一个此代码存在问题 - 如果您查看错误窗格,它将为您提供问题所在的文本说明。 (双击错误消息,它将直接指向错误的行。)


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
​
namespace Lab4
{
    class Program
    {
        static void Main(string[] args)
​
        {
            SavingAccount aSavingAccount;
            List<savingaccount> accounts = new List<savingaccount>();
            while (true)
            {
                Console.Write("Please enter the account owner's name: ");
                string Owner = Console.ReadLine();
​
                if (Owner == "")
                    break;
​
                Console.Write("Please enter the initial deposit amount for the saving account: ");
                string entry1 = Console.ReadLine();
                double InitialDepositAmount = double.Parse(entry1);
               
                Console.Write("Please enter the monthly deposit amount for the saving account: ");
                string entry2 = Console.ReadLine();
                double MonthlyDepositAmount = double.Parse(entry2);
​
                aSavingAccount = new SavingAccount(Owner, InitialDepositAmount);
                aSavingAccount.MonthlyDepositAmount = MonthlyDepositAmount;
​
                accounts.Add(aSavingAccount);
​
            } 
​
            foreach (SavingAccount account in accounts)
            {
                for(int i = 0; i < 6; i++)
                {
                    account.Withdraw(SavingAccount.MonthlyFee);
                    account.Deposit(account.MonthlyDepositAmount);
                    account.Deposit(SavingAccount.MonthlyInterestRate * account.Balance);
                }
                Console.WriteLine("After 6 months, {0}'s account (#{1}), has a balance of: {2:C}", account.Owner, account.AccountNumber, account.Balance);
            }
            
        }
    }



What I have tried:

I tried to run in another window of visual studio but its showing all red line errors for full line code

解决方案

To start with, C# is case sensitive, so

SavingAccount aSavingAccount;

Is not the same class as

List<savingaccount> accounts = new List<savingaccount>();

And since they are different classes, the latter can';t contain instances of the former! Plus, one is probably wrong so the compiler is probably telling you "I can't find class XXX".

The "Red Lines" are telling "there is a problem with this code" - if you look at the Errors pane it will give you a text description of what the problem is. (Double click the error message, and it'll take you direct to the line in error.)


这篇关于Console.writeline不起作用,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆