Cannot implicitly convert type 'object' to 'bool' Error

  • Thread starter Patrick Olurotimi Ige
  • Start date
P

Patrick Olurotimi Ige

When i convert:- this code from VB to C#
Why do i get error "Cannot implicitly convert type 'object' to 'bool'


VB
---
If cmdcommand.Parameters("ReturnValue").Value = 1 Then
lblStatus.Text = "Username already exists!"
Else
lblStatus.Text = "Success!"
End If


to

C#
---
if (cmdcommand.Parameters["ReturnValue"].Value == 1) {
lblStatus.Text = "Username already exists!";
} else {
lblStatus.Text = "Success!";
}
 
B

bruce barker

cmdcommand.Parameters["ReturnValue"].Value return an object. you can not
compare objects to numbers. if you know the type of the return value, then
you can cast it, and do the compare

if ( (int) cmdcommand.Parameters["ReturnValue"].Value == 1)

this will throw an error is the parameter is no really an int.





| When i convert:- this code from VB to C#
| Why do i get error "Cannot implicitly convert type 'object' to 'bool'
|
|
| VB
| ---
| If cmdcommand.Parameters("ReturnValue").Value = 1 Then
| lblStatus.Text = "Username already exists!"
| Else
| lblStatus.Text = "Success!"
| End If
|
|
| to
|
| C#
| ---
| if (cmdcommand.Parameters["ReturnValue"].Value == 1) {
| lblStatus.Text = "Username already exists!";
| } else {
| lblStatus.Text = "Success!";
| }
|
|
| Don't just participate in USENET...get rewarded for it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top