read-eval-print-loopscriptcs

Unable to use toString() in scriptcs?


This seems like a really silly question, but I'm really stuck, so here goes:

Normally, when I would want to use toString() I would write

int i = 50;
string str = i.toString();

According to .NET Pearls, this is a correct usage. After all, toString() is a method in the Object class. But scriptcs tells me:

error CS1061: 'int' does not contain a definition for 'toString' and no extension method 'toString' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?)

Okay, maybe this can't work for some reason, let's try using the System.Convert class:

error CS0117: 'System.Convert' does not contain a definition for 'toString'

I tried ading usings and even loading the mscorlib.dll assembly, but no luck. This happens to me both when interpreting a file and when using the REPL. I am really stuck on stupid string conversion and I'm begging for help. If it changes anything, I got scriptcs from chocolatey. Scriptcs version 0.9.0; .NET version 4.0.

#r "mscorlib.dll"
using System;
using System.Convert;

int i = 50;

string str = Convert.toString(i);
//string str2 = i.toString(); //uncomment to get the other error

Console.WriteLine(str);

Is string.Format(), StringBuilder and "" + value all I have?


Solution

  • It's casing. C# is case sensitive and the method is called ToString.