D
D
dobrikv2017-03-01 17:48:12
.NET
dobrikv, 2017-03-01 17:48:12

When I try to compile, I get an error - The input string had an invalid format, what's the problem?

class Program
    {
        static void Main(string[] args)
        {
            SportCar SC = new SportCar("green", 2000, 250, 7, true);
            Console.WriteLine("SC.color ={ 0},SC.ves ={ 1},SC.power ={ 2},SC.transmission ={ 3},SC.complete_drive{ 4}", SC.color, SC.ves, SC.power, SC.transmission, SC.complete_drive);
            Console.ReadLine();
        }
    }
    class Car
    {
        public string color;
        public int ves;
        public int power;

        public Car(string color, int ves, int power)
        {
            this.color = color;
            this.ves = ves;
            this.power = power;
        }
    }
    class SportCar : Car
    {
        public short transmission;
        public bool complete_drive;

        public SportCar(string color,int ves, int power, short transmission,bool complete_drive)
            :base(color,ves,power)
        {
            this.transmission = transmission;
            this.complete_drive = complete_drive;
        }
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Tom Nolane, 2017-03-01
@dobrikv

here (problem) with spaces:
remove spaces:
(where { 0}, { 1} ... need {0}, {1})

A
Artem, 2017-03-01
@devspec

So clean, for information. Visual Studio 2015 allows you to do this:
which, in my opinion, is prettier and avoids such errors. Note the $ sign in front of the string - that's its magic. You can do this with any line, not just in Console.WriteLine.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question