Skip to content

Instantly share code, notes, and snippets.

@vcsjones
Created November 7, 2013 14:26
Show Gist options
  • Save vcsjones/7355394 to your computer and use it in GitHub Desktop.
Save vcsjones/7355394 to your computer and use it in GitHub Desktop.
List<string> aList = null;
foreach(var str in aList) {...}
//How I really wish this compiled:
var enumerator = aList == null ? null : aList.GetEnumerator();
try {
while (enumerator != null && enumerator.MoveNext()) {
var element = (ElementType)enumerator.Current;
//statement;
}
}
finally {
IDisposable disposable = enumerator as System.IDisposable;
if (disposable != null) disposable.Dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment