相关疑难解决方法(0)

运算符'=='不能应用于'char'和'string'类型的操作数

我有一个注册申请,里面有"KeyChar"活动,它很棒!但是当我在这个应用程序中给出相同的代码行时,它给了我Operator '=='/'!=' cannot be applied to operands of type 'char' and 'string'

似乎无法弄清楚为什么它在其他应用程序中工作但不在这里!任何帮助深表感谢 !

 private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        SqlConnection DBConnection = new SqlConnection("Data Source=DATABASE;Initial Catalog=imis;Integrated Security=True");
        SqlCommand cmd = new SqlCommand();

        Object returnValue;

        string txtend = textBox1.Text;
        //string lastChar = txtend.Substring(txtend.Length - 1);

        if (e.KeyChar == "L")
        {
            DBConnection.Open();
        }
        if (DBConnection.State == ConnectionState.Open)
        {
            if (textBox1.Text.Length != 7) return;
            {
                //cmd.CommandText = ("SELECT last_name +', '+ first_name +'\t ('+major_key+')\t' from name where id =@Name");
                cmd.CommandText …
Run Code Online (Sandbox Code Playgroud)

c# winforms

3
推荐指数
1
解决办法
8799
查看次数

在C#中,将字符串解析为单个字符

在C#中,如何将字符串解析为单个字符?
鉴于:
word ="精彩";

期望的结果:
字母[0] ='W';
字母[1] ='o';
字母[2] ='n';
字母[3] ='d';
字母[4] ='e';
字母[5] ='r';
字母[6] ='f';
信[7] ='你';
信[8] ='l';

c# string parsing character

2
推荐指数
2
解决办法
2万
查看次数

错误运算符'=='无法应用于'char'和'string'类型的操作数

我收到下面的错误,我不知道如何解决它.我只是想学习,但不能想出这个.我尝试用等号(=)替换它,并且有很多东西但没有用,代码是:

if (keyinfo.KeyChar == "a") 
{

}
Run Code Online (Sandbox Code Playgroud)

这是错误:

0019运算符'=='不能应用于'char'和'string'类型的操作数

如何避免出现此错误?

c# string error-handling equals char

-6
推荐指数
1
解决办法
871
查看次数

标签 统计

c# ×3

string ×2

char ×1

character ×1

equals ×1

error-handling ×1

parsing ×1

winforms ×1