Re: Emulating String.Format compile-time functionality



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/
.



Relevant Pages

  • Re: Implementing a stack-based interpreter
    ... > been able to find anything on how to write a stack-based interpreter. ... > [Compile to a string of reverse polish operators, ... it is very unusual for compilers to compile everything down to ... formatted output and Fortran's FORMAT) usually involves ...
    (comp.compilers)
  • Re: formatter
    ... So is a function that can take a control ... eliminates 's need to parse the control string ... the <format> is embedded in some iterative structure. ... FORMATTER allows you to compile the format control ...
    (comp.lang.lisp)
  • Re: Date format detection
    ... Specifies the locale for which the date string is to be formatted. ... date format for this locale. ... the system default-date format for the specified locale. ... be enclosed within single quotation marks in the date format picture. ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Date format detection
    ... > Specifies the locale for which the date string is to be formatted. ... > date format for this locale. ... > the system default-date format for the specified locale. ... > be enclosed within single quotation marks in the date format picture. ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Date confusion
    ... Read my reply elsewhere in this string. ... > integer portion of the value represents the date as the number of days ... >> If you are working with a numeric date and you want the format DDMMYYYY, ... Another reason for preferring to store a date as text would be personal preference. ...
    (microsoft.public.access.modulesdaovba)