I'm a new developer in C# and I'm migrating code from VB.NET to C#. But the LIKE operator is not working in C#, is there another one with the same function?
The VB.NET code I need to convert looks like this::
If (item Like "[A-D]") Then
End If
If (item Like "[E-H]") Then
End If
If (item Like "[I-M]") Then
End If
If (item Like "[N-V]") Then
End If
CodePudding user response:
LIKE operator does not exist for C#, the solution is to use regular expression.
try this:
if (Regex.IsMatch(item, "^[a-dA-D] $"))
{
}
if (Regex.IsMatch(item, "^[e-hE-H] $"))
{
}
if (Regex.IsMatch(item, "^[i-mI-M] $"))
{
}
if (Regex.IsMatch(item, "^[n-vN-V] $"))
{
}