String.Equals() not working as intended

前端 未结 6 727
再見小時候
再見小時候 2020-11-28 10:49

I am using LINQ to search through one of my Entity Framework tables and find a \"group\" based on the name. The name is a string and appears to be Unicode (says it is in the

6条回答
  •  北海茫月
    2020-11-28 11:31

    Try name.Equals(gr.Name, StringComparison.OrdinalIgnoreCase)

    If it works then the problem could be with gr.Name.

    --- Edit ---

    I'm guessing that gr.Name is not of type System.string. (since String.Equals gives you an error ==> from the previous post)

    give this a shot

    (gr.Name as string).Equals(name, StringComparison.OrdinalIgnoreCase)
    

    or

    String.Equals((gr.Name as string), name, StringComparison.OrdinalIgnoreCase)
    

提交回复
热议问题