为了账号安全,请及时绑定邮箱和手机立即绑定

使用断点调试时,其余参数正常,,但strlist的值为null?这是哪里错了?

使用断点调试时,其余参数正常,,但strlist的值为null?这是哪里错了?

C# C
HUWWW 2022-06-01 11:07:24
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace WindowsFormsApplication1{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){}private void button1_Click(object sender, EventArgs e){double corpusAmount, interestRate,interestAmount, incomeAmount;int depositYear; //本金,利率,利息,总收入,存期try // 录入数据{corpusAmount = double.Parse(this.corpusTextbox.Text);interestRate = double.Parse(this.interestRatetextBox.Text);depositYear = Int32.Parse(this.depositYeartextBox3.Text);}catch //异常处理{MessageBox.Show(" Input dismatached !");return;}incomeAmount = corpusAmount * (Math.Pow((1 + interestRate), depositYear)); //计算总收入interestAmount = incomeAmount - corpusAmount; //计算利息//格式化列表string strList;strList = string.Format(" {0,15:c } {1,15:c } ", interestAmount, incomeAmount);listBox1.Items.Add(strList); //输出```}}}
查看完整描述

3 回答

?
陪伴而非守候

TA贡献1757条经验 获得超8个赞

c后面 不要空格
double value1 = 16932.456;
double value2 = 15421.354;// {0,15:c } {1,15:c } 这个有空格 错误的
string result = String.Format("{0,15:c} {1,15:c}", value1, value2);

查看完整回答
反对 回复 2022-06-06
?
跃然一笑

TA贡献1826条经验 获得超6个赞

strList = string.Format(" {0,15:c } {1,15:c } "
这个是啥?{}里面不是占位符吧
format的用法是string.Format("{0},{1}",value1,value2);
{0}{1}都是占位符,分别对应value1和value2的值

查看完整回答
反对 回复 2022-06-06
?
繁星淼淼

TA贡献1775条经验 获得超11个赞

返回的是2个double数值,一个得息,一个总收到,你用string.Format把他们转换成字符串,比如一个数是10.59,另一个数是11.49,stringList="10.59$11.49$"(15:C应该表示货币吧),你查下interestAmount,和incomeAmount有值么?

查看完整回答
反对 回复 2022-06-06
  • 3 回答
  • 0 关注
  • 170 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号