Skip to content

Instantly share code, notes, and snippets.

@controlflow
Created March 27, 2017 12:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save controlflow/bb51c6b251542dead945ad1fc947c49c to your computer and use it in GitHub Desktop.
Save controlflow/bb51c6b251542dead945ad1fc947c49c to your computer and use it in GitHub Desktop.
while (ReferenceNameNavigator.GetByQualifier(referenceName) != null)
referenceName = ReferenceNameNavigator.GetByQualifier(referenceName);
while (ReferenceNameNavigator.GetByQualifier(referenceName) is var byQualifier && byQualifier != null)
referenceName = byQualifier;
@ViIvanov
Copy link

Looks like the same

Q qualifier;
while ((qualifier = ReferenceNameNavigator.GetByQualifier(referenceName)) != null)
  referenceName = qualifier;

but more easy..?

@controlflow
Copy link
Author

controlflow commented Apr 5, 2017

@ViIvanov yep, and with a less-scoped variable

@glenn-slayden
Copy link

glenn-slayden commented Dec 12, 2019

"Less-scoped" is nice; the minimalist aesthetic should be more widely celebrated.

In this vein, why not just eliminate the excess variable entirely?

while (referenceName != (referenceName = ReferenceNameNavigator.GetByQualifier(referenceName) ?? referenceName))
    ;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment