Re: Emulating String.Format compile-time functionality
- From: Barry Kelly <barry.j.kelly@xxxxxxxxx>
- Date: Tue, 10 Apr 2007 17:40:37 +0100
Rick wrote:
With String.Format, if I have an incorrect number of args specified for a
format string, compile fails.
No it doesn't. This compiles just fine for me, but fails at runtime:
---8<---
~$ cat test.cs
class App
{
static void Main()
{
string.Format("{0} {1}", "foo");
}
}
~$ csc test.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.
~$ ./test
Unhandled Exception: System.FormatException: Index (zero based) must be
greater than or equal to zero and less than the size of the argument
list.
at System.Text.StringBuilder.AppendFormat(IFormatProvider provider,
String format, Object[] args)
at System.String.Format(IFormatProvider provider, String format,
Object[] args)
at App.Main()
--->8---
-- Barry
--
http://barrkel.blogspot.com/
.
- Follow-Ups:
- Re: Emulating String.Format compile-time functionality
- From: Rick
- Re: Emulating String.Format compile-time functionality
- From: Bill Butler
- Re: Emulating String.Format compile-time functionality
- References:
- Prev by Date: Re: Win32 API for Search!
- Next by Date: Re: Serialization...
- Previous by thread: Emulating String.Format compile-time functionality
- Next by thread: Re: Emulating String.Format compile-time functionality
- Index(es):
Relevant Pages
|