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"
My aspx page looks like this
Text='<%# isCommentNC(Eval("nc_resultName").ToString()) %>'
and my cs page contains 开发者_运维知识库this method
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?
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
Are you sure your data doesn't contain any blanks before or after? Try Trimming your string before calling Equals on it...
I have the following nc_resultsName values being returned from my dataset "NC-1" , "NC-2" , "C"
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.
Make sure the debugger isn't playing tricks on you.
精彩评论