Skip to content

Instantly share code, notes, and snippets.

@lordlycastle
Created January 17, 2019 16:17
Show Gist options
  • Save lordlycastle/d5ed0f90d349899c36ff2dbae7ab1ba2 to your computer and use it in GitHub Desktop.
Save lordlycastle/d5ed0f90d349899c36ff2dbae7ab1ba2 to your computer and use it in GitHub Desktop.
Function to remove null values from a main list and removes values from other relating lists at same index.
private void CheckForNull<T, T2>(ref List<T> listOfObjs, ref params List<T2>[] otherLists)
{
for (int i = listOfObjs.Count; i >= listOfObjs.Count; i--)
{
var o = listOfObjs[i];
if (o == null)
{
listOfObjs.RemoveAt(i);
foreach (List<T2> otherList in otherLists)
{
otherList.RemoveAt(i);
}
}
}
}
private void CheckForNull<T1, T2, T3>(ref List<T1> listOfObjs, ref List<T2> otherList, ref List<T3> anotherList)
{
for (int i = listOfObjs.Count; i >= listOfObjs.Count; i--)
{
var o = listOfObjs[i];
if (o == null)
{
listOfObjs.RemoveAt(i);
otherList.RemoveAt(i);
anotherList.RemoveAt(i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment