vb.net - ?: Operator in VB to C# -
i used online converter convert piece of visual basics code c#. next code in vb:
dim aset new dataset aset = *code* dim str string = "" dim str7 string = "" dim str4 string = "" dim str10 string = "" if (if(((str7 = str10) andalso (str7 <> "")), 1, 0) = 0) str7 = conversions.tostring(aset.tables.item(0).rows.item(i).item("pin")) end if if (i <> 0) str4 = (str4 & " ,") end if str4 = (str4 & str) str10 = str7 += 1
was converted next c# code:
dataset aset = new dataset(); aset = *code* string str = ""; string str7 = ""; string str4 = ""; string str10 = ""; if ((((str7 == str10) && (str7 != "")) ? 1 : 0 == 0)) { str7 = conversions.tostring(aset.tables[0].rows[i]["pin"]); } if ((i != 0)) { str4 = (str4 + " ,"); } str4 = (str4 + str); str10 = str7; += 1;
my questions deal ?: operator. tried research on it, still little confusing me. receive error in c# version says "type of conditional look cannot determined because there no implicit conversion between 'int' , 'bool'." when changed next c# piece of code:
if ((((str7 == str10) && (str7 != "")) ? 1 : 0 == 0))
to next piece of code:
if ((((str7 == str10) && (str7 != "")) ? 1 == 0: 0 == 0)) //i changed '1' '1 == 0'
the error seems go away. however, not convinced correctly fixed error programme doing in vb code or if solution altered purpose of piece of code. help appreciated allow me know if did correct, or need do.
the c# translation wrong, , vb terrible.
class="lang-vb prettyprint-override">if (if(((str7 = str10) andalso (str7 <> "")), 1, 0) = 0)
is
class="lang-vb prettyprint-override">if if(((str7 = str10) andalso (str7 <> "")), 1, 0) = 0
is
class="lang-vb prettyprint-override">if not ((str7 = str10) andalso (str7 <> ""))
is
class="lang-vb prettyprint-override">if not (str7 = str10) orelse not (str7 <> "")
is
class="lang-vb prettyprint-override">if str7 <> str10 orelse str7 = ""
. equivalent c# if (str7 != str10 || str7 == "")
.
c# vb.net operators
No comments:
Post a Comment