How to see if two variables are not equal [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I knew that you can check if variables are equal with = or ==, but can you check if it is less than or greater that with < >, but is there a way to check if two variables are not equal, but instead diffrent

In most modern programming languages, this is accomplished with the use of the ! in front of the = sign as in !=
a != b (Used in C# and others)
Or
a <> b (Useful if your program is using additional languages)
and sometimes you use it like
NOT a == b (Again, useful if your program is calling another language that uses this form.)

Use the not equal to != operator?
if (a != b)
{
}

Related

If Conditional Statement Checking always check only the first condition in C# ASP.NET [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I've some checking condition with If..Then..Else.. statement but I've something happened that keep confusing me with this problem. My code was :
if ( !context.APIPOS_ExportPos.Any(x => x.CustomerRef == HAWBToUpdate) || !context.Export_Reguler.Any(y => y.CustomerRef == HAWBToUpdate) )
{
//some complicated operation goes here...
}
It's always check the first condition before OR Operator ( || ) and the condition after OR Operator was not checked.
What should I do to solve this problem ? Many thanks for your help
Why don't you just use && instead of ||.
The problem of your code is that when a condition became true, it doesn't need to check further conditions.

Convert.ToInt32("example") Collisions? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Will the C# function Convert.ToInt32(text) convert different words to the same int? Any links or pushes in the right direction are appreciated!
P.S.
What about anagrams?
No, Convert.ToInt32(text) will just try to parse your text to an int, like:
Convert.ToInt32("032") will return 32 as int but
Convert.ToInt32("Brian") will throw an exception.
I assume that you want to have some kind of hashing, when you say "different words to the same int".
Try GetHashCode(). It will return the same value if you call it multiple times with the same value, for example:
"Brian".GetHashCode() will always return 1635321435

Conversion of C# code to Delphi code (if condition) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I'm converting a C# project to Delphi and am struggling with this C# code:
if (!String.IsNullOrEmpty(myItem.mySubItem?.Content) && (myItem.Quantity == 0) && (String.IsNullOrEmpty(myItem.Description)))
{
continue;
}
From my understanding the Delphi code should look like this:
if assigned(myItem.mySubItem) and (length(trim(myItem.mySubItem.Content)) > 0) and (myItem.Quantity = 0) and (length(trim(myItem.Description)) = 0) then begin
Continue;
end;
But I'm not 100% sure, because logically it doesn't make sense. That's another story though. My question is: is my Delphi code a correct conversion of the quoted C# code?
In case it's wrong, what would be the correct code?
You are trimming the delphi strings before checking against a length of 0. In c#, a string containing only spaces is not 'NullOrEmpty'.

What's the equivalent of Delphi's RoundTo() in C#? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
What's the equivalent of Delphi's RoundTo() in C#?
I am not very familiar with Delphi and I am aware of C#'s Math.Round() but am not sure how equivalent they are. Math.Round() has several overloads and RoundTo() has two.
The equivalent method is Math.Round. You need to use the overload which offers the functionality that you need, whatever that is.
The Delphi RoundTo function is not overloaded and is best matched with this overload of Math.Round:
public static double Round(
double value,
int digits
)

Why Reflector ver 7 produced wrong Linq code like this [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
private FileStorageFolder GetCapsuleContentFolder(FileStorageDataContext db)
{
IQueryable<FileStorageFolder> source = from dbFolder in db.FileStorageFolders
where (dbFolder.ParentID == null) && (dbFolder.Purpose == reportFolderPurpose)
select dbFolder into dbFolder
join dbSubFolder in db.FileStorageFolders on dbFolder.ID equals
dbSubFolder.ParentID into dbSubFolder
where (dbSubFolder.Purpose == capsulelayoutFolderPurpose) &&
(dbSubFolder.FolderName == capsuleReportContent)
select dbSubFolder;
Instrument.Assert(source.Count<FileStorageFolder>() == 1);
return source.Single<FileStorageFolder>();
}
this is not correct syntax.Does anyone know how to create IQueryable typed base on this?
If it is problematic, try cranking down the "Optimisation" setting to, say, .NET 2.0. This will then be forced to display the explicit .Select(...) etc. This should produce correct C#, but without the LINQ style.
Note, however, that it may also reverse the apparent call-order, since it will probably use explicit extension-method representation. The code should be equivalent either way, though.

Categories

Resources