猿问

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

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); //输出```
}
}

}

HUWWW
浏览 171回答 3
3回答

陪伴而非守候

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);

跃然一笑

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

繁星淼淼

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