According to this post :
is this overkill for assessing Main(string[] args)
It seems that args can never be null in
static void Main(string[] args)
Ok good to know, however, supposing args.Length == 1 is true is it possible to have args[0] == null ? First observation : A string array can have null elements
Second observation : If the main is invoked with the command line I wouldn't know how to pass null and I don't think it is possible,
Third observation : on the other hand (this is a bit far-fetched) it is possible that some code calls
Program.Main(new string[]{null})
Thus, it is possible to produce a case where one gets null values in the args array.
So the question is :
Is it overkill or good practice to make tests for nullity in the main's arguments ? (Especially considering that the main called like in the third observation is an unlikely case)
For example : is the following correct ?
static void Main(string[] args)
{
if(args.Length == 1)
{
var v = args[0].Replace("Foo", "Bar");//hope args[0] is not null
or should I rather do
static void Main(string[] args)
{
if(args.Length == 1 && args[0] != null)
{
//...
Note: I tagged it C# but I guess this applies to other languages as well