C
C#2y ago
pan Scott

how to format multiple conditions assignments in return statement [CLOSED] [Answered]

Greetings, I was wondering, how could I properly format this piece of code.
return
res > PageCount ?
-1
:
isLastPage ?
resint > PageItemCount(ItemCount / ItemsPerPage) ?
-1
:
resint
: resint;
return
res > PageCount ?
-1
:
isLastPage ?
resint > PageItemCount(ItemCount / ItemsPerPage) ?
-1
:
resint
: resint;
You can see I tried to format it somehow, but I don't think it looks good. :D
11 Replies
jcotton42
jcotton422y ago
the way you format that is by changing it to if/if else/else my eyes are crossing just trying to read that
pan Scott
pan Scott2y ago
I thought that cond assign is faster than if else in most cases
jcotton42
jcotton422y ago
no there's no perf difference not sure where you got that idea from
pan Scott
pan Scott2y ago
I saw it somewhere, but it was with strings, not ints that's why probably
jcotton42
jcotton422y ago
still doesn't make a difference
pan Scott
pan Scott2y ago
and it was in cpp
jcotton42
jcotton422y ago
just change to regular if statements wouldn't be different there either
jcotton42
jcotton422y ago
that's due to a quirk of how C++ handles declarations
std::string blah;
blah = condition ? if-true : if-false;
std::string blah;
blah = condition ? if-true : if-false;
and
std::string blah;
if(condition) {
blah = if-true;
} else {
blah = if-false;
}
std::string blah;
if(condition) {
blah = if-true;
} else {
blah = if-false;
}
would perform exactly the same also that nested ternary in the video is an unreadable abomination the guy in the video is trying to be really clever but in a bad way don't be "clever" like that, you'll hate yourself down the line
pan Scott
pan Scott2y ago
well he's not exactly one of my favourites okay thanks for help
Accord
Accord2y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server
More Posts
Entity Framework One-To-One [Answered]Code at: https://paste.mod.gg/rccwzntafwoj/0 When attempting to change the database I'm getting: TDatabase - Relationship returns empty set even though records are present [Answered]I think I'm probably missing something stupid obvious... In my batch model, I have ```cs private reaSave storageFile to a folder on driveI have a storagefile ready to give to a control to crop an image the problem is that image crop wilDynamically load .dll into .NET 6 ProgramHi, I've a Blazor WebAssembly Hosted (.NET 6) web application. I've put some part of the applicationMove File To A Matching Type RefactoringWhen everything is top-level do you not need namespaces because everything is "top-level"? Thanks foClass making my program run as a background process after I close it [Answered]https://paste.myst.rs/7o8qz5vk After I close my program through RMB>Close window it continues runniHangfire - Unable to resolve services [Answered]Working with Hangfire. I have a plugin service which has an InitializeAsync method that looks like tASP.NET Website project without namespaces. Converting to ASP.NET Web application.Hi guys, I have a legacy ASP.NET Website project which I want to convert to ASP.NET Website applicatBest Way to Save Client_Secret and access_token?Hey i got now the Discord Login on my Tool Ready but now i need to Safe Data like the Access_token, How do I call a null event?```csharp public delegate void MyDel(); public event MyDel MyEvent; public void Le