I\'m using a linq query to output an int array. But I need to pass this into a method that only accepts int?[].
So after searching on ways to convert int[] to int?[] I
Don't do the wrong thing first, and then fix it up afterwards. Do the right thing straigtaway. You know you need an int?[]. So create an int?[]. Don't first create an int[] and then fix it up. You can get it to work, but it's pointlessly complicated.
int?[] vids1 = new[] { "", "1", "2", "3" }
.Where(x => !String.IsNullOrWhiteSpace(x))
.Select(x => (int?) Convert.ToInt32(x))
.ToArray();
The reason I'm strongly suggesting not even trying to make your ToArrayOrNull work is also because it doesn't even come close to doing what you're saying it should do. You can make it work, but you have to understand what's supposed to be going on before starting on your coding. Leave this for now as long as you don't need it anyway, and when you look back later you'll probably suddenly see it.