✅ Possible bug in ternary operator when incrementing in razorpages?
inside some .cshtml:
@{
int a;
int k;
if(Model.SomeArray != null)
{
a = Model.SomeArray[0].SomeIndex;
}
for(int i=0; i<Model.SomeOtherArray.Length; i++)
{
if(i==a)
{
//do somework
k = (k+1 < Model.SomeArray.Length) ? k++ : k;
}
}
}
correct me if im wrong but k should increment here and then be saved? or is the ternary operator scope localized and the parameter get incremented in another scope and the obj ref then dropped, meaning that the work is lost?
in razor pages k++, or even k=k++; doesnt update the object. k=k+1 works though. This should be a bug right?
4 Replies
It's not a bug, if you want to increment and assign you would do
k=++k
Though why not just do
ahaha, got bit in the ass by the assignment ordering . I don't want too keep nesting, this is just the start of the component and its already starting to become a nightmare, thank you! c:
It's not assignment ordering,
k++
is postfix increment it returns the original value before the increment essentially
right post and prefix, never learnt the terms correctly. thank you