包含Unicode字符检查失败 [英] Contains Unicode Character checking fail

查看:129
本文介绍了包含Unicode字符检查失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public bool ContainsUnicodeCharacter(char[] input)
    {
        const int MaxAnsiCode = 255;
        bool temp;
        string s;

        foreach (char a in input)
        {
            s = a.ToString();
            temp = s.Any(c => c > MaxAnsiCode);

            if (temp == false)
            {
                return false;
            }
        }
    }





此代码用于检查输入字符是否存在unicode数组。

我收到错误信息:ContainsUnicodeCharacter(char [])'':并非所有代码路径都返回一个值



什么这里出了问题,请帮忙。谢谢。



This code used to check unicode exist or not on input char array.
I got error message : " ContainsUnicodeCharacter(char[])'': not all code paths return a value"

What went wrong here, Please help. Thank You.

推荐答案

当没有任何字符属于<时,你必须添加 return ... code> if branch。

干杯

Andi

PS:使用 temp 作为变量是坏。如果你没有给变量一个合适的名字你可能不知道你做了什么;-)

PPS:这个函数不是顾名思义:已经127以上的字符可能是unicode!
You must add a return... when none of the characters fall into the if branch.
Cheers
Andi
PS: using temp as a variable is "bad". If you fail to give a decent name to a variable your probably don''t know what you do ;-)
PPS: This function does not what the name suggests: already a character above 127 might be unicode!


在它落到最后的情况下,您忘记返回一个值。因此也可以简化:



You forgot to return a value in the case where it falls through to the end. It could also be simplified thus:

public bool ContainsUnicodeCharacter(char[] input)
{
    const int MaxAnsiCode = 255;

    foreach (char a in input)
    {
        if (a > MaxAnsiCode)
            return true;
    }
    return false;
}


这篇关于包含Unicode字符检查失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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