As already pointed out by others there is no Like operator in C#.
Also it is not available in VB.Net for .net standard. (It has been added again for .net)
I had the case that the pattern is a user input. Migrating to net standard, my only option was therefor to implement it myself. I chose to convert the pattern to an equivalent regular expression:
<Extension()> Public Function VbLike(str As String, pattern As String) As Boolean Dim resultPattern = New Text.StringBuilder Dim insideList = False Dim prevInsideList = False For i = 0 To pattern.Length - 1 Dim c = pattern(i) Dim tempInsideList = insideList ' Manage pattern start If i = 0 AndAlso c <> "*"c Then resultPattern.Append("^"c) End If ' Manage characterlists If c = "["c AndAlso Not insideList Then insideList = True resultPattern.Append(c) ElseIf c = "]"c AndAlso insideList Then insideList = False resultPattern.Append(c) ' Special chars for Like that need to be converted ElseIf c = "!"c AndAlso insideList AndAlso Not prevInsideList Then resultPattern.Append("^"c) ElseIf c = "?"c AndAlso Not insideList Then resultPattern.Append("."c) ElseIf c = "#"c AndAlso Not insideList Then resultPattern.Append("\d") ElseIf c = "*"c AndAlso i = 0 Then ' Nothing to append ElseIf c = "*"c AndAlso i = pattern.Length - 1 Then ' Nothing to append ElseIf c = "*"c AndAlso Not insideList Then resultPattern.Append(".*") ' Special chars for Regex that need to be escaped ElseIf c = "."c OrElse c = "\"c OrElse c = "("c OrElse c = ")"c Then resultPattern.Append("\"c) resultPattern.Append(c) Else resultPattern.Append(c) End If ' Manage pattern end If i = pattern.Length - 1 AndAlso c <> "*"c Then resultPattern.Append("$"c) End If prevInsideList = tempInsideList Next Return Regex.IsMatch(str, resultPattern.ToString, RegexOptions.Singleline Or RegexOptions.IgnoreCase Or RegexOptions.CultureInvariant) End Function
.Where(x => x.EndsWith("email");might be appropriate.Likeoperator in C#, in this case you can useString.EndsWith(if this isLinq-To-Objects), otherwise you need to use regex orSqlMethods.Like( if it'sLinq-To-Sql).Likeoperator to a C# equivalent whereas the other question is the SQLLIKEoperator, different things...where LikeOperator.LikeString(mySourceString, "*Something*", CompareMethod.Text)It's in theMicrosoft.VisualBasic.CompilerServicesnamespace. Further info here: msdn.microsoft.com/en-us/library/…