Cannot Convert from 'string' to 'System.Iformatprovider'

Asked

Viewed 1,676 times

2

Follow the code (works):

var teste = 1;
var teste1 = teste.ToString("000000");

Upshot:

000001

Follow another code (does not work):

var teste = "1";
var teste1 = teste.ToString("000000");

Upshot:

cannot Convert from 'string' to 'System.Iformatprovider'

How can I convert string for ToString with a result "000001"?

1 answer

4


It makes no sense to convert string for string, already is string. Let alone you can convert string for ToString() which is a method and not a type.

If you want to put zeros in front of the number use the PadLeft().

using static System.Console;

public class Program {
    public static void Main() {
        var teste = "1";
        WriteLine(teste.PadLeft(6, '0'));
    }
}

Behold working in the ideone. And in the .NET Fiddle. Also put on the Github for future reference.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.