简体   繁体   English

string.Equals不能按预期在asp.net Webforms中工作

[英]string.Equals is not working as I expected in asp.net webforms

I have the following nc_resultsName values being returned from my dataset "NC-1" , "NC-2" , "C" 我的数据集“ NC-1”,“ NC-2”,“ C”返回了以下nc_resultsName值

My aspx page looks like this 我的aspx页面如下所示

Text='<%# isCommentNC(Eval("nc_resultName").ToString()) %>'

and my cs page contains this method 我的cs页面包含此方法

    public Func<string, bool> isCommentNC = x => x.Equals("NC-1") || x.Equals("NC-2");

but my method only behaves correctly if I use Contains instead... Why? 但是我的方法仅当我改用Contains时才能正确运行...为什么?

    public Func<string, bool> isCommentNC = x => x.Contains("NC-1") || x.Contains("NC-2");

* EDIT * 编辑

Sorry Mistyped changed "C" to "NC-1" , same issue though 对不起,类型错误,将“ C”更改为“ NC-1”,但同样存在问题

I have the following nc_resultsName values being returned from my dataset "NC-1" , "NC-2" , "C" 我的数据集“ NC-1”,“ NC-2”,“ C”返回了以下nc_resultsName值

How are you determining that? 您如何确定? If you're looking in the debugger, it's possible that an embedded null character is playing tricks on you. 如果您正在调试器中查找,则可能是嵌入式的空字符正在对您起到欺骗作用。 .NET strings can contain those characters, but the debugger stops displaying the string at that point, as if they are C-style strings. .NET字符串可以包含这些字符,但是调试器会在此时停止显示该字符串,就好像它们是C样式的字符串一样。

Make sure the debugger isn't playing tricks on you. 确保调试器没有在欺骗您。

Are you sure your data doesn't contain any blanks before or after? 您确定您的数据前后没有空格吗? Try Trimming your string before calling Equals on it... 在调用Equals之前,尝试修剪字符串...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM