您好我想在TID变量之后命名一个文件,该变量是用户在streamwriter
中输入的交易号。交易ID也是下面的transactionIDLabel.Text
。我想知道如果我可以将事务ID(int TID
或TranasactionIDLabel.Text
)设为文本文件的名称?感谢。
int TID;
private void button2_Click(object sender, EventArgs e)
{
StreamWriter outputFile;
outputFile = File.CreateText ("TID.txt");
outputFile.WriteLine(InvestorNameLabel.Text);
outputFile.WriteLine(AmountLabel.Text);
outputFile.WriteLine(DateLabel.Text);
outputFile.WriteLine(DaysInvestedLabel.Text);
outputFile.WriteLine(RateLabel.Text);
outputFile.WriteLine(InterestAmountLabel.Text);
outputFile.WriteLine(TransactionIDLabel.Text);
outputFile.Close();
}
答案 0 :(得分:2)
试
outputFile = File.CreateText (TID.ToString()+".txt");
答案 1 :(得分:0)
试试这个:
using(StreamWriter sw=new StreamWriter(string.Concat(TransactionIDLabel.Text,".txt")))
{
// Your code
}