Asp.net隐式无法将CHAR转换为BOOLEAN [英] Asp.net IMPLICITLY CANNOT CONVERT CHAR TO BOOLEAN

查看:111
本文介绍了Asp.net隐式无法将CHAR转换为BOOLEAN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,帮助...
错..
隐式无法将CHAR转换为BOOLEAN

Hi pls help...
Eror..
IMPLICITLY CANNOT CONVERT cHAR TO BOOLEAN

if (ds2.Tables[0].Rows.Count > 0)
                {
                    int i = 0,j=0,k=0;
                    int count = 0;
                    char[] arr1=new char[ds2.Tables[0].Rows[0][0].ToString().ToCharArray().Length];
                    char[] result = new char[ds2.Tables[0].Rows[0][0].ToString().ToCharArray().Length];
                   while (i < ds2.Tables[0].Rows.Count)
                    {
                       arr1 = ds2.Tables[0].Rows[i]["PrivilegeID"].ToString().ToCharArray();
                       if(i==0)
                       {
                           result=ds2.Tables[0].Rows[i+1]["PrivilegeID"].ToString().ToCharArray();
                       }
                       count = arr1.Length;
                       for (j = 0; j < count; j++)
                       {
                            result[j] = Convert.ToChar(Convert.ToBoolean(arr1[j]) || Convert.ToBoolean(result[j]));
                            //result[j]= Convert.ToChar((Convert.ToBoolean(arr1[j]))||(Convert.ToBoolean(result[j])));
                       }
                        i++;
                    }
                    i = 0;

推荐答案

如果您查看Convert.ToBoolean(char) [
正是您所得到的.
那么,为什么要尝试将char转换为bool?为什么不将char与期望的char值的"true"或"false"值进行比较?
If you look at the definition of Convert.ToBoolean(char)[^] you will see:
"Calling this method always throws InvalidCastException."
Which is exactly what you are getting.
So, why are you trying to convert a char to a bool? Why not compare the char with the "true" or "false" values you expect for the char value?


您将返回值转换为此处的字符数组-result=ds2.Tables[0].Rows[i+1]["PrivilegeID"].ToString().ToCharArray();. />
您将无法直接将此数组的元素转换为布尔值.
You convert the return value to a character array here - result=ds2.Tables[0].Rows[i+1]["PrivilegeID"].ToString().ToCharArray();.

You wont be able to convert an element of this array directly to boolean.


这篇关于Asp.net隐式无法将CHAR转换为BOOLEAN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆