I have a code:
byte[][][] file = GetConfigData();
if (file == null)
return;
int pages = 0;
for (i = 0; i < file.Length; i++)
{
if (file[i] != null)
{
for (j = 0; j < file[i].Length; j++)
{
if (file[i][j] != null)
{
pages++;
}
}
}
}
How can I simplify it ?
Please, provide 2 versions:
- for .net 2.0
- for .net 3.5 (linq)
If you mean ‘how can I make it easier to understand’, then my number one suggestion would be to use more meaningful variable names.
It will be longer but simpler.
You could also use ‘foreach’ instead of ‘for’ – that would lose some of the index variables anyway.
And finally you could use some hairy linq line to do it all in a functional style, but that won’t be ‘simpler’ in any beginner’s sense.