I have following methods:
float myMethod(MyObject[][] myList)
{
float a = 0;
if (myListProcessingMethod(myList?.Where(x => x.mySatisfiedCondition()).ToList()))
{
a = 5;
}
return a;
}
bool myListProcessingMethod(List<MyObject[]> myList)
{
bool isSuccess = false;
if (myList.Any())
{
isSuccess = true;
}
return isSuccess;
}
I consider this condition:
if (myListProcessingMethod(myList?.Where(x => x.mySatisfiedCondition()).ToList()))
I refactor my condition to:
if (myList?.Length != 0)
{
if (myListProcessingMethod(myList.Where(x => x.mySatisfiedCondition()).ToList()))
{
a = 5;
}
}
Is this two conditions are equivalent? What is equivalent condition to first NullConditionOperator in traditional way? What is equivalent condition to second traditional checking using NullConditionalOperator?
List<T>doesn't have aLengthproperty. Did you meanCount? Could you provide a minimal reproducible example and test the code for yourself first? Note that ifmyListis null,myList?.Countis null, which isn't equal to 0 - so you'd then end up with an exception.return myList.Any();essentially.if (myList?.Any(x => x.satisfiesCondition()) ?? false) { a = 5; }?