C#int to String ...在Textbox中输出

时间:2017-03-22 14:44:22

标签: c# string int calculator

我是C#的新手 我试图编写一个小的加法计算器。

    string jsonStudentData = @"{""Name"":""ABC"",""Subjects"":[{""Name"":""English""},{""Name"":""Maths""},{""Name"":""Hindi""},{""Name"":""Social Studies""}]}";
    JavaScriptSerializer serializer = new JavaScriptSerializer();
    Student  newStudent = serializer.Deserialize<Student>(jsonStudentData);

我的问题是如何修复它?

2 个答案:

答案 0 :(得分:1)

我猜您正在寻找ToString()方法。您可以在每个对象上调用此方法,也可以覆盖该方法;如果需要的话。

在你的button1_Click方法中使用此

textBox1.Text = a.ToString();

答案 1 :(得分:0)

一般情况下,请尝试使用格式;如果是C#6.0 + 字符串插值

     private void button1_Click(object sender, EventArgs e) {
       textBox1.Text = $"{z + 1}";
     }

如果是C#5.0- string.Format

     private void button1_Click(object sender, EventArgs e) {
       textBox1.Text = string.Format("{0}", z + 1);
     }

请注意如何轻松编码和阅读:

     textBox1.Text = $"My old value is {z} and incremented one {z + 1}";