#If statement within if statement
1 messages · Page 1 of 1 (latest)
depends how you use it but in most cases no
...it depends on how much, really
if you gonna stack 10 if's in each other its probably bad
When it comes to performance, I think you need to benchmark. Always.
https://www.youtube.com/watch?v=EWmufbVF2A4
Become a Patreon and get source code access: https://www.patreon.com/nickchapsas
Check out my courses: https://nickchapsas.com
Hello everybody I'm Nick and in this .NET tutorial we will take a first look at benchmarking our .NET code using BenchmarkDotNet. BenchmarkDotNet is a nuget package that allows us to run benchmarks against our C# method...
benchmark a singular if inside another one? damn, you must be slow.
I mean, in general.
I just think asking questions about performance is a bad idea in general, because there are no good answers other than, "Benchmark it."
Even if it wasn't bad for performance its still not optimal
Why would you intentionally make your code look like shit
Time consuming aswell
You can put an if-statement on multiple lines if you want to as well. 😅
if (extremelyLongBooleanExpression
&& anotherExtremelyLongBooleanExpression)
just a couple of if statements are still really fast, if you check simple bool states,
what determines if it's slow or not is what you actually evaluate inside the if checks and other code, like what methods you call for the if check and their execution time
cool thing I really like to do is
void SomeFunction()
{
if(!Something)
return;
if(!SomethingElse)
return;
DoStuff();
}
inverse the statement and return early
doesn't always work, but when it does, it usually improves readability
This is called a guard clause btw
good to know, thanks