简体   繁体   English

用C#将int转换为textbox.text

[英]int to textbox.text with C#

With VB I have no error with this method 使用VB我没有这种方法的错误

Private Sub But_Leer_Click(sender As Object, e As EventArgs) Handles But_Leer.Click

    Dim INT(3) As Integer
    ProEasy.ReadDevice32("LT4000_1.#INTERNAL", "Valor1", INT, 1)
    TextBox1.Text = INT(0)

But with C#, I have an error when assigning "Valor" int to Textbox1.text. 但是对于C#,将“ Valor” int分配给Textbox1.text时出现错误。 A string is required: 字符串是必需的:

private void button2_Click(object sender, EventArgs e)
    {
        int[] Valor = new int[3];
        ProEasy.ReadDevice32("LT4000_1.PLC1", "MWO", out Valor, 1);
        textBox1.Text = **Valor**[0];

Anyone knows why? 有人知道为什么吗? I just starting with VB and C# language 我只是从VB和C#语言开始

The Text property of the TextBox control requires a string . TextBox控件的Text属性需要一个string Valor is an array containing integer values. Valor是一个包含整数值的数组。 Therefore you will have to cast that value to string. 因此,您将必须将该值转换为字符串。

textBox1.Text = Valor[0].ToString();

Valor[0]返回int ,您需要将其转换为string

textBox1.Text = Valor[0].ToString();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM