what package?namespace? do I need to make use of String.Format() for C# programs?

I've found a bunch of C# reference materials on how to format strings using String.Format()


 timeText = String.Format ("{0:00}:{0:00}:{1:00}:{0:00}",displayDays,displayHours, displayMinutes, displaySeconds);

But ... when I write a C# script in Unity I attempting to make use of String.Format() I get the error message:

The name "String" does not exist in the current content

So I assume I need to add a "using .." statement at the top of of the script file .. but which one?

Using String; doesn't work

any help much appreciated ...

"String" = Javascript, "string" = C#.

okay - slightly odd - I found a different article that used "string.Format()" (i.e. lower case "s")

and this solves the problem :-)

since I assume (perhaps wrongly) that I'm not the only person who might find this odd, I'll leave my question and answer posted, so it might help someone else save 20 minutes trying to get String.Format() rather than string.Format() working in C# scripts

happy coding ... matt ..

You need ...

using System;

here's a more explicit version of my final working code (simplified for exposition):

void OnGUI()
        float displayDays = 13;
        float displayHours = 9;
        float displayMinutes = 32;
        float displaySeconds = 55;
        string timeText = System.String.Format ("{0:00}:{0:00}:{1:00}:{0:00}",displayDays,displayHours, displayMinutes, displaySeconds);
        GUILayout.Label("time = " + timeText );


This has been very illuminating - it is very useful to learn about these "aliases" of classes to act as primitive types (personally I've never been happy with primitive types in any OO language, they spoil the clarity and simplicity of taking an objects-only view - I've always had a softspot for Smalltalk ...)

I found the following link useful, which summarises a list of aliases and the actual classes they are aliases for:


while UnityAnswers keeps asking me if I want to answer my own question, I keep saying yes ... since I think this discussion is something useful for people like me who can program (I've been programming for over 30 years - they keep on creating new programming concepts like design patterns and object-orientation, and lots of new languages like Python and ActionScript) but are new to C# and unity ...

now to get back to that pacman tile-based world game sample I'm getting ready for my lecture on Friday to some year 2 BSc computing students...

.. matt ..