i format string using system.string.format
has 5 overloads:
string string.format(string format , object arg0 ) string string.format(string format , object arg0 , object arg1 ) string string.format(string format , object arg0 , object arg1 , object arg2 ) string string.format(string format , params object[] args ) string string.format(iformatprovider provider , string format , params object[] args )
i use fourth overload (the 1 takes array of objects) this:
let frm = "{0} - {1}" let args = [| 1; 2 |] system.string.format(frm, args)
the problem args argument interpreted object , hence first overload called. correctly following error:
system.formatexception: index (zero based) must greater or equal 0 , less size of argument list.
is there way force "correct" overload?
a more elegant variant of @john's answer add type annotation compiler automatic upcast on elements of array:
let frm = "{0} - {1}" let args : obj [] = [| 1; 2 |] system.string.format(frm, args)
Comments
Post a Comment