mardi 31 mars 2015

weird behavior of string.Format method [duplicate]


This question already has an answer here:




Why am I getting runtime exception at line



Console.WriteLine(string.Format("Hello World {0}", null)); //Runtime


while line



Console.WriteLine(string.Format("Hello World {0}", a));


works fine even though string a is null?



using System;

public class Program
{
public static void Main()
{
string a = null;

Console.WriteLine(string.Format("Hello World {0}", a));
Console.WriteLine(string.Format("Hello World {0}", null)); //Runtime exception! Why?
}
}


Here is DotNetFiddle


Aucun commentaire:

Enregistrer un commentaire