c# – 拆分字符串时出现混乱错误
发布时间:2020-12-15 20:03:45 所属栏目:百科 来源:网络整理
导读:我有这行代码: string [] ids = Request.Params [“service”] .Split(“,”); Request.Params [“service”]中的值为:“1,2” 我为什么得到: Error 1 The best overloaded method match for 'string.Split(params char[])' has some invalid argumentsEr
我有这行代码:
string [] ids = Request.Params [“service”] .Split(“,”); Request.Params [“service”]中的值为:“1,2” 我为什么得到: Error 1 The best overloaded method match for 'string.Split(params char[])' has some invalid arguments Error 2 Argument 1: cannot convert from 'string' to 'char[]' 这对我来说没有意义…. 错误发生在等号右侧的所有内容上 解决方法
您需要传递一个字符(System.Char),而不是字符串:
string[] ids = Request.Params["service"].Split(',');
如果要使用字符串(或多个字符串)进行拆分,则需要使用字符串[]并指定拆分选项: string[] ids = Request.Params["service"].Split(new[]{","},StringSplitOptions.None); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |