Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Hey guys I've been getting this on some code I've been working on for school. Been googling it for hours but can't find anything, any help would be appreciated.
Code:
if (dogName = "" || lstDogBreeds.SelectedIndex = -1)
Error:
Operator '||' cannot be applied to operands of type 'string' and 'int'
= is assignment operator, == is equality operator.
You use = for setting variables, like int numberOfApples = 20;
And you use == for checking if two things are equal, like
if (numberOfApples == 20)
{
//do stuff
}
the operator to compare if equal is ==
if(dogName == "" || lstDogBreeds.SelectedIndex == -1)
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 months ago.
Improve this question
I have this linq query in my controller and it is working fine,
var Engineers = dbcontext.Employees.Where(i => i.Department == "Engineers");
but I would like to add a second condition to the query to filter out the results,
var Engineers = dbcontext.Employees.Where(i => i.Department == "Engineers" && i.UserStatus = 1);
Thanks for your help.
You made a typo, just need to use comparison operator (==) instead of assignation (=)
So it would be like that:
var Engineers = dbcontext.Employees.Where(i => i.Department == "Engineers" && i.UserStatus == 1);
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I just need it to check if the variable "remaining" equals 0
To check equality in C# use == operator.
if(remaining == 0){
// write your logic
}
Use the == operator
if(remaining == 0){
// write your logic
}
The == operator checks whether the LHS = RHS or not whereas
= is an assignment operator it is used to assign values like int a = 10;
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
when I try to use TryParse I get error CS0029, pls see below:
static void Main(string[] args)
{
double m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12;
double notval = 0;
Console.WriteLine("Please insert the rainfall in January:");
m1 = double.TryParse(Console.ReadLine(), out notval) ;
I get the error "Cannot implicitly convert type 'bool' to 'double'" (CS0029).
TryParse returns of it was successful at parsing or not, and puts the result (if successful) in the out parameter (on you case notval).. so use:
if(double.TryParse(Console.ReadLine(), out notval))
{
// Do what you want with notval
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm trying to write the following LINQ query...
string userSearch = textBoxSearchUserInput.Text;
//LINQ query for Member name search
var MemberNameSearch =
from member in context.Members
where String.Compare(userSearch, member.MemberLastName, true) = 0
select member;
But I'm getting the error message in the title.
What I'm trying to achieve, comparing two strings while ignoring the case
Thanks
where String.Compare(userSearch, member.MemberLastName, true) == 0
To compare you need to use ==
This would work
String.Equals(userSearch, member.MemberLastName, StringComparison.OrdinalIgnoreCase)
You should change it
where String.Compare(userSearch, member.MemberLastName, true) = 0
To
where String.Compare(userSearch, member.MemberLastName, true) == 0
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
How to check if a label is visible?This is not working...
if(labelFS.Visible = false)
{do sth}
else//labelFS.Visible = true
{do other}
solved
Use == to compare two values, not the assignment operator (a single =).
By using a single =, you're actually setting the value of labelFS.Visible to False, which hides it.
(There's also no need to type out true and false .)
if (labelFS.Visible)
// do something
else
// do something else
I'd suggest reading up on the difference. Here's a start...
Equality Operator (==)
Assignment Operator (=)
if(labelFS.Visible == false)
{do sth}
else//labelFS.Visible == true
{do other}
Use == instead of =