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

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'.

Related

Check for uppercase and lowercase letters 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 1 year ago.
Improve this question
How can I not check for just uppercase or lowercase letters.
if(textBox1.Text == "StackOverFlow")
{
//Some Code
}
If I type stackoverflow it would count it as false. But if it is typed as StackOverFlow the exact word it would be counted as true. Please help.
if(textBox1.Text.ToLowerInvariant() == "stackoverflow")
{
// Some code
}
"StackOverFlow".Equals(textBox1.Text, StringComparison.OrdinalIgnoreCase)
Use the String.Equals method.
By using StringComparison-Option StringComparison.OrdinalIgnoreCase your two strings will be compared ignoring the casing.

If Statement help mutiple and, or statements [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 1 year ago.
Improve this question
if (((Input.GetKeyDown(KeyCode.A)) && (Input.GetKeyDown(KeyCode.LeftShift))) || ((Input.GetKeyDown(KeyCode.RightShift)) && (Input.GetKeyDown(KeyCode.A))))
{
print("Well done! Next Key: " + "A");
}
What's Wrong with this if statement?
It looks like you have too many parentheses on the left side of the OR. Also, your parentheses are not correct on the right side. I believe you want to set it up like this.
if (Input.GetKeyDown(KeyCode.A) && (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift)))
Edit: Revised because checking for A twice is redundant as pointed out by #Caius-jard.

Error converting C# code to VB.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 6 years ago.
Improve this question
I have the following C# code
charValue = text[charIndex++];
Via the C# to VB.NET converter at converter.telerik.com, it has given me this code:
charValue = text (
System.Math.Max(
System.Threading.Interlocked.Increment(charIndex),charIndex - 1))
However, when I copy the converted code in, I am getting an error.
charValue = text[charIndex++];
in C# is shortcut for
charValue = text[charIndex];
charIndex += 1;
and in VB.Net:
charValue = text(charIndex)
charIndex += 1

What does (int) mean 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 6 years ago.
Improve this question
I've encountered sometimes code like this and I am kind of new to programming. I want to find out what's the meaning behind those objects or data type enclosed in parenthesis.
(int)
(datagridview)
(form)
If you see something like this it's called a cast. It's used to explicitly convert a data type to another data type.
double pi = 3.14159;
int my_int = (int)pi;
See this description on casting for more details.

How to see if two variables are not equal [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 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)
{
}

Categories

Resources