I am working on a code conversion from VB.NET to C#. I found this piece of code which I am trying to wrap my head around but I can't get how it is evaluated:
If eToken.ToLower = False Then _
Throw New Exception("An eToken is required for this kind of VPN-Permission.)
My problem is with the comparison between a string eToken.ToLower and a boolean value False.
I tried to use a converter and what I got was as follow (which is not a valid statement in C# as you cannot compare a string to a bool):
if (eToken.ToLower() == false) {
throw new Exception("An eToken is required for this kind of VPN-Permission.");
}
I compiled it and decompiled the IL; in C# that is:
string eToken = "abc"; // from: Dim eToken As String = "abc" in my code
if (!Conversions.ToBoolean(eToken.ToLower()))
{
throw new Exception("An eToken is required for this kind of VPN-Permission.");
}
So there's your answer: it is using Conversions.ToBoolean (where Conversions is Microsoft.VisualBasic.CompilerServices.Conversions in Microsoft.VisualBasic.dll)
You can do a type cast assuming, eToken has a value of "true"/"false":
if (Convert.ToBoolean(eToken.ToLower())==false)
throw new Exception("An eToken is required for this kind of VPN-Permission.");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With