本文介绍了当stringbuilder进行转换时显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有C#编码...

在此我使用stringbuilder ...因此,当stringbuilder值转换为int时,它会显示一些错误,例如
"无法将类型为"System.Text.StringBuilder"的对象转换为类型为"System.IConvertible".

我的编码是这个

I have C# coding...

In this I using stringbuilder...So when stringbuilder value converts to int it shows some error like
""Unable to cast object of type ''System.Text.StringBuilder'' to type ''System.IConvertible"".

my coding is this

if (username.Length > 0)
               {
                   StringBuilder details = objectfororderdetails.GetUsernamelocked(UserName, lockedout);
                   lbllockuser.Text = "Username and his/her Restaurants Successfully locked";
                   if (Convert.ToInt16(details) == 0)
                   {
                       txtlockuser.Text = null;
                       lbllockuser.Text = "Username and his/her Restaurants already locked";
                   }
               }



当运行时出现if(Convert.ToInt16(details)== 0)时,显示如我上面提到的错误.


为此解决方案提供任何解决方案



when runtime comes in if(Convert.ToInt16(details) == 0) it shows error like i mentioned above.


Give any solution for this

推荐答案


Convert.ToInt16(details.ToString())


请记住一次,stringbuilder不是字符串,您不能将其用作字符串.


Remember for once, stringbuilder is not string, you cannot use it as a string.


StringBuilder details = new StringBuilder();
           details.Append("0");

           string detailsStr = details.ToString();

           if (detailsStr == "0")
           {

           }



问候,
T



Regards,
T


这篇关于当stringbuilder进行转换时显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 16:42