![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I am a VB programmer tring to learn C# I am stuck on a bit operator "&" in VB: ' checkLogin = 3 means "Login exists" and "Employee Number exists" If (checkLogin And 1) Then lbError.Text = "Login already exists" End If If (checkLogin And 2) And txtEmpNum.Text <> 0 Then lbError.Text &= "Employee Number already exists" End If I did this in C#: if(checkLogin & 1) { lbError.Text = "Login already exists"; } if((checkLogin & 2) & txtEmpNum.Text.Length > 0 ) { lbError.Text = "Employee Number already exists"; } Error: Cannot implicitly convert type 'int' to 'bool' -- Thanks in advance, Dave |
#3
| |||
| |||
|
|
I am a VB programmer tring to learn C# I am stuck on a bit operator "&" in VB: ' checkLogin = 3 means "Login exists" and "Employee Number exists" If (checkLogin And 1) Then lbError.Text = "Login already exists" End If If (checkLogin And 2) And txtEmpNum.Text <> 0 Then lbError.Text &= "Employee Number already exists" End If I did this in C#: if(checkLogin & 1) { lbError.Text = "Login already exists"; } if((checkLogin & 2) & txtEmpNum.Text.Length > 0 ) { lbError.Text = "Employee Number already exists"; } Error: Cannot implicitly convert type 'int' to 'bool' -- Thanks in advance, Dave |
#4
| |||
| |||
|
|
I am a VB programmer tring to learn C# I am stuck on a bit operator "&" in VB: ' checkLogin = 3 means "Login exists" and "Employee Number exists" If (checkLogin And 1) Then lbError.Text = "Login already exists" End If If (checkLogin And 2) And txtEmpNum.Text <> 0 Then lbError.Text &= "Employee Number already exists" End If I did this in C#: if(checkLogin & 1) { lbError.Text = "Login already exists"; } if((checkLogin & 2) & txtEmpNum.Text.Length > 0 ) { lbError.Text = "Employee Number already exists"; } Error: Cannot implicitly convert type 'int' to 'bool' -- Thanks in advance, Dave |
#5
| |||
| |||
|
|
logical expression must be composed of boolean operands. int is not boolean. you'll have to write it like this int a; (checkLogin && (a == 1)) { ... } by asking if a's value is some value you have made boolean expression out of int . numerical value doesn't evaluate to true/false (c# being strongly typed, unlike c++). also && is logical operator and & bitwise "Dave" wrote: I am a VB programmer tring to learn C# I am stuck on a bit operator "&" in VB: ' checkLogin = 3 means "Login exists" and "Employee Number exists" If (checkLogin And 1) Then lbError.Text = "Login already exists" End If If (checkLogin And 2) And txtEmpNum.Text <> 0 Then lbError.Text &= "Employee Number already exists" End If I did this in C#: if(checkLogin & 1) { lbError.Text = "Login already exists"; } if((checkLogin & 2) & txtEmpNum.Text.Length > 0 ) { lbError.Text = "Employee Number already exists"; } Error: Cannot implicitly convert type 'int' to 'bool' -- Thanks in advance, Dave |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |