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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top