拆分字符串时令人困惑的错误 [英] Confusing error when splitting a string

查看:127
本文介绍了拆分字符串时令人困惑的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这行code的:

的String [] = IDS Request.Params [服务]斯普利特();

Request.Params [服务] 是值: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[]'

这是没有意义的我....

This makes no sense to me....

这一切发生在等号的右边

The error happens on everything to the right of the equal sign

推荐答案

您需要传递一个字符( System.Char ),而不是一个字符串

You need to pass a character (System.Char), not a string:

string[] ids = Request.Params["service"].Split(',');

有没有超载 String.Split ,需要一个 PARAMS字符串[] 或一个字符串,这是什么会被要求作出您code的工作。

There is no overload to String.Split that takes a params string[] or a single string, which is what would be required to make your code work.

如果你想用一个字符串(或多个字符串),你就需要使用的String [] ,并指定拆分选项分裂:

If you wanted to split with a string (or multiple strings), you would need to use a string[] and specify splitting options:

string[] ids = Request.Params["service"].Split(new[]{","}, StringSplitOptions.None);

这篇关于拆分字符串时令人困惑的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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