Unable to check if integer is equal to zero [closed] - c#

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;

Related

How to add a second condition in Linq Query [closed]

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);

How to check if a string contains any letter besides Z [closed]

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 4 years ago.
Improve this question
I am trying to check to see if this object contains any letters besides Z and if it does it should return Null. The way I have it initialized gives me no errors but when testing it does not actually return null if a letter is present.
if(request.DoorTag.Contains(#"[a - yA - Y]"))
{
return null;
}
if(Regex.IsMatch(request.DoorTag, "[a-yA-Y]")
{
return null;
}
But "[^zZ]" would even be better, since it'll check that your DoorTag contains any other char than Z

Linq and String.Compare - the left hand side of an assignment must be a variable [closed]

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

C# operator issues [closed]

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)

Check if a label has visible property to true.c# winforms [closed]

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 =

Categories

Resources