运算符*不能应用于操作数C#

运算符*不能应用于操作数C#,c#,C#,试图提出贷款申请,但我发现这是一个错误 运算符*不能应用于textbox和int类型的操作数 运算符*不能应用于textbox和double类型的操作数 我的代码如下所示 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using Sy

试图提出贷款申请,但我发现这是一个错误

运算符*不能应用于textbox和int类型的操作数 运算符*不能应用于textbox和double类型的操作数

我的代码如下所示

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyApp3
{
    public partial class LoanApplication : Form
    {
        double InterestRate, monthlyInterestRate, loanAmount, monthlyPayment, TotalPayment;
        int NoOfyears;

        private void button1_Click(object sender, EventArgs e)
        {
            InterestRate = Convert.ToDouble(rate.Text);
            monthlyInterestRate = InterestRate / 1200;
            NoOfyears = Convert.ToInt32(noOfYrs.Text);
            loanAmount = Convert.ToDouble(txtLoanAmt.Text);

            monthlyPayment = loanAmount * monthlyInterestRate / (1 - 1 / Math.Pow(1 + monthlyInterestRate,noOfYrs * 12)); // This Line

            iMonthlyPayment = Convert.ToString(monthlyPayment);
            iMonthlyPayment = String.Format("{0:C}", monthlyPayment);
            monthly_payment.Text = (iMonthlyPayment);

            TotalPayment = monthlyPayment * noOfYrs * 12; // This Line
            iTotalPayment = String.Format("{0:C}", TotalPayment);
            total_payment.Text = (iTotalPayment);

            txtLoanAmt.Text = String.Format("{0:C}", txtLoanAmt.Text);
        }

        string iMonthlyPayment, iTotalPayment;
        public LoanApplication()
        {
            InitializeComponent();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void LoanApplication_Load(object sender, EventArgs e)
        {
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
        }
    }
}

我在这里到底遗漏了什么?

您正在尝试执行textbox*int。textbox是对象,您不能将其乘以int-it-Double。您需要首先从textbox中获取值并将其转换为int或Double。例如:int.Parse(myTextbox.Text)*myInt

在有问题的行中,您正在使用变量
noOfYrs
,它是一个文本块,而不是
NoOfyears
,后者是一个整数。

错误消息的哪一部分看起来不清楚?@mustaccio This line monthlyPayment=loanAmount*monthlynterestate/(1-1/Math.Pow)(1+MonthlyInterestate,noOfYrs*12);**这一行**TotalPayment=monthlyPayment*noOfYrs*12;在C#中,标识符是区分大小写的。请阅读关于发布代码的指南-显然,这篇文章中的代码墙远远超出了演示问题的必要性。
(int)myTextbox.Text
:)哥们,这是错误的。你的意思是int.Parse(myText.Text)或Convert…是的,我的错。我想解决了。非常感谢。