I'm experimenting with Zip operations in C#, like described here. Considering this code snippet:
int[] numbers = new[] { 1, 2, 3, 4 };
string[] words = new string[] { "one", "two", "three", "four" };
var numbersAndWords = numbers.Zip(words, (n, w) => new { Number = n, Word = w });
foreach (var nw in numbersAndWords)
{
Console.WriteLine(nw.Number + nw.Word);
}
What is a proper way to avoid System.ArgumentNullException
in case one of the components are null
?
For example, initializing words
to null, like this
int[] numbers = new[] { 1, 2, 3, 4 };
string[] words = null;
// The next line won't work
var numbersAndWords = numbers.Zip(words, (n, w) => new { Number = n, Word = w });
Obs: I'm actually working with Directory.EnumerateDirectories
and Directory.EnumerateFiles
instead of int[]
and string[]
.