Understanding the code snippet

I am doing C #, with no experience with VB, and I don't have VB. I look at the code below to understand how this works, can someone take a look at this?

So, if I call this method with Cat and Cat and do not pass an optional parameter, does it return true and say that Cat and Cat are equal?

 Public Function AreStringsEqual(ByRef sString1 As String, ByRef sString2 As String, Optional ByVal eCompareMethod As VbCompareMethod = vbBinaryCompare) As Boolean If LenB(sString1) = LenB(sString2) Then If LenB(sString1) = 0 Then AreStringsEqual = True ElseIf eCompareMethod = vbBinaryCompare Then AreStringsEqual = (InStrB(1, sString1, sString2, eCompareMethod) <> 0) Else AreStringsEqual = (StrComp(sString1, sString2, eCompareMethod) = 0) End If End If End Function 
+4
source share
1 answer

Here is some weird code. In any case, the default value for the third argument is vbBinaryCompare , which means that "Cat" and "Cat" will not compare evenly. To compare them you need to go through vbTextCompare .

Now that's why the code is strange: it is completely redundant. You can just call StrComp directly.

+12
source

Source: https://habr.com/ru/post/1444853/


All Articles