意外的文本(System.Int32 [])

时间:2013-05-08 16:09:56

标签: c#

我正在尝试制作一个代码,用于计算通过键盘输入的按键的保持时间和按下/释放时间。

hold time = keyup(i) - keydown(i+1)
release_press time = keydown(i+1) - keyup(i)
press_press time = keydown(i+1) - keydown(i)
release_release time = keyup(i+1) - keyup(i)

这是我的代码既没有错误也没有警告...但是当我运行它时,我得到(System.Int32[])文本框中应该展示保持和按下/释放时间。我不知道为什么我会收到错误或错误在哪里。

Form1.cs的

    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;
    using Domainnn;
    using Sessionnn;


    namespace TheLatestKS
    {
         public partial class Form1 : Form
{
    Brokerrr b = new Brokerrr();
    public Form1()
    {
        InitializeComponent();
    }

    int i = 0;
    private void timer1_Tick(object sender, EventArgs e)
    {
        i++;
    }

    int[] A=new int[25];
    int[] B=new int[25];
    int[] C=new int[25];
    int[] D=new int[25];
    int[] M=new int[25];
    int[] N=new int[25];
    int[] O=new int[25];
    int[] P=new int[25];

    private void textBox2_KeyDown(object sender, KeyEventArgs e)
    {
        timer1.Enabled = true;

        for (int a = 0; a < textBox2.TextLength; a++)
        {
            timer2.Enabled = true;
            M[a] = k;
            if (a >= 1)
            {
                O[a] = k;
            }
        }
    }

    int j = 0;
    int s = 0;
    float ave = 0;
    private void button1_Click(object sender, EventArgs e)

        {
            timer1.Enabled = false;
            textBox5.Text = i.ToString() + " ms";
            s = s + i;
            Personnn p = new Personnn();
            p.Username = textBox1.Text;
            p.Password = textBox2.Text;
            p.Totaltyping = label5.Text;
            p.Keyduration = textBox3.Text;

            textBox4.Text += textBox2.Text + Environment.NewLine;

            if (j >= 2)
            {
                ave = s / 3;
                textBox6.Text = ave.ToString() + " ms";
            }

            p.Meanoftotal = textBox6.Text;
            p.UDlatency1 = textBox8.Text;
            p.DDlatency1 = textBox9.Text;
            p.UUlatency1 = textBox10.Text;

            b.Insert(p);

            textBox1.Text = " ";
            textBox2.Text = " ";
            textBox3.Text = " ";
            textBox8.Text = " ";
            textBox9.Text = " ";
            textBox10.Text = " ";

            i = 0;

            j++;

        }

    private void textBox1_KeyDown(object sender, KeyEventArgs e)
    {

        if ((e.KeyValue < 65 || e.KeyValue > 122) && (e.KeyValue != 32) && (e.KeyValue != 8))
        {
            label7.Text = "Only letters are allowed";


        }

        if (e.KeyValue ==  8)
        {
            label7.Text = " ";
        }
    }

    private void textBox2_KeyUp(object sender, KeyEventArgs e)
    {
        for (int a = 0; a < textBox2.TextLength; a++)
        {
            timer2.Enabled = true;
            N[a] = k;
            if (a >= 1)
            {
                P[a] = k;
            }

        }

        for (int ii = 0; ii <textBox2.TextLength; ii++)
        {
         A[ii] = N[ii] - M[ii];// key duration
        }

        for (int iii = 0; iii < textBox2.TextLength-1; iii++)
        {
         B[iii] = O[iii] - N[iii];//UD latency
         C[iii] = O[iii] - M[iii];//DDlatency
         D[iii] = P[iii] - N[iii];//UU latency
        }

        textBox3.Text = A.ToString();// key duration

        textBox8.Text = B.ToString();// UD latency

        textBox9.Text = C.ToString();// DD latency

        textBox10.Text = D.ToString();// UU latency

    }

    int k = 0;
    private void timer2_Tick(object sender, EventArgs e)
    {
        k++;
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void label8_Click(object sender, EventArgs e)
    {

    }

}
    }

Personnn.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace Domainnn
    {
public class Personnn
{
    int id;

    public int Id
    {
        get { return id; }
        set { id = value; }
    }
    string username;

    public string Username
    {
        get { return username; }
        set { username = value; }
    }
    string password;

    public string Password
    {
        get { return password; }
        set { password = value; }
    }

    string totaltyping;

    public string Totaltyping
    {
        get { return totaltyping; }
        set { totaltyping = value; }
    }

    string meanoftotal;

    public string Meanoftotal
    {
        get { return meanoftotal; }
        set { meanoftotal = value; }
    }

    string keyduration;

    public string Keyduration
    {
        get { return keyduration; }
        set { keyduration = value; }
    }

    string UDlatency;

    public string UDlatency1
    {
        get { return UDlatency; }
        set { UDlatency = value; }
    }
    string DDlatency;

    public string DDlatency1
    {
        get { return DDlatency; }
        set { DDlatency = value; }
    }
    string UUlatency;

    public string UUlatency1
    {
        get { return UUlatency; }
        set { UUlatency = value; }
    }
}
    }

Brokerrr.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
using Domainnn;

namespace Sessionnn
{
    public class Brokerrr
    {
        OleDbConnection connection;
        OleDbCommand command;

        private void ConnectTo()
        {
            connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\S.M.A.S\Documents\Visual Studio 2010\Projects\TheLatestKS\Databaseee.accdb");
            command = connection.CreateCommand();

        }
        public Brokerrr()
        {
            ConnectTo();
        }

        public void Insert(Personnn p)
        {
            try
            {
                command.CommandText = "INSERT INTO Table1 ([Username], [Password], Totaltyping, Meanoftotal, Keyduration, UDlatency, DDlatency ,UUlatency) VALUES('" + p.Username + "', '" + p.Password + "', '" + p.Totaltyping + "', '"+p.Meanoftotal+"', '"+p.Keyduration+"', '"+p.UDlatency1+"', '"+p.DDlatency1+"', '"+p.UUlatency1+"')";
                command.CommandType = CommandType.Text;
                connection.Open();

                command.ExecuteNonQuery();
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }
    }
}

2 个答案:

答案 0 :(得分:2)

问题在于以下几行:

textBox3.Text = A.ToString();// key duration

ToString()方法不会生成包含您的数字的字符串。它只是告诉你类型是什么。这是默认的ToString行为。

int显示该号码,因为它们有一个被覆盖的ToString方法。

你可能想要

A[i].ToString();

或者您可能想要制作某种数组的聚合字符串,在这种情况下,您可以编写一个函数或其他内容来执行此操作。

答案 1 :(得分:2)

当你说

textbox3.Text = A.ToString();

在int数组上调用ToString,并且因为int []没有重写的ToString,所以它调用Object.ToString来打印类型名称:Int32 []

如果您尝试返回所有元素,则有多种方式,包括:

string.Join(" ", A)