{"id":17163,"date":"2009-08-10T10:00:00","date_gmt":"2009-08-10T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2009\/08\/10\/why-doesnt-string-format-throw-a-formatexception-if-you-pass-too-many-parameters\/"},"modified":"2009-08-10T10:00:00","modified_gmt":"2009-08-10T10:00:00","slug":"why-doesnt-string-format-throw-a-formatexception-if-you-pass-too-many-parameters","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20090810-00\/?p=17163","title":{"rendered":"Why doesn&#039;t String.Format throw a FormatException if you pass too many parameters?"},"content":{"rendered":"<p>\nWelcome to CLR Week 2009.\nAs always, we start with a warm-up.\n<\/p>\n<p>\nThe <code>String.Format<\/code> method doesn&#8217;t throw a\n<code>FormatException<\/code>\nif you pass too many parameters,\nbut it does if you pass too few.\nWhy the asymmetry?\n<\/p>\n<p>\nWell,\nthis is the type of asymmetry you see in the world a lot.\nYou need a ticket for each person that attends a concert.\nIf you have too few tickets, they won&#8217;t let you in.\nIf you have too many,\nwell, that&#8217;s a bit wasteful, but you can still get in;\nthe extras are ignored.\nIf you create an array with 10 elements and use only the first five,\nnobody is going to raise an <code>ArrayBiggerThanNecessary<\/code> exception.\nSimilarly, the\n<code>String.Format<\/code> message doesn&#8217;t mind if you pass\ntoo many parameters; it just ignores the extras.\nThere&#8217;s nothing harmful about it, just a bit wasteful.\n<\/p>\n<p>\nBesides, you probably don&#8217;t want this to be an error:\n<\/p>\n<pre>\nif (verbose) {\n  format = \"{0} is not {1} (because of {2})\";\n} else {\n  format = \"{0} not {1}\";\n}\nString.Format(format, \"Zero\", \"One\", \"Two\");\n<\/pre>\n<p>\nThink of the format string as a <code>SELECT<\/code> clause\nfrom the dataset provided by the remaining parameters.\nIf your table has fields <code>ID<\/code> and <code>NAME<\/code>\nand you select just the <code>ID<\/code>, there&#8217;s nothing wrong\nwith that.\nBut if you ask for <code>DATE<\/code>, then you have an error.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to CLR Week 2009. As always, we start with a warm-up. The String.Format method doesn&#8217;t throw a FormatException if you pass too many parameters, but it does if you pass too few. Why the asymmetry? Well, this is the type of asymmetry you see in the world a lot. You need a ticket for [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-17163","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Welcome to CLR Week 2009. As always, we start with a warm-up. The String.Format method doesn&#8217;t throw a FormatException if you pass too many parameters, but it does if you pass too few. Why the asymmetry? Well, this is the type of asymmetry you see in the world a lot. You need a ticket for [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/17163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=17163"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/17163\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=17163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=17163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=17163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}