Hey i have a problem with my C# problem under the class cars. On each public declaration it is saying that it already contains a definition for 'idNumber', 'make', 'model', 'color', and 'cost'. I am using windows visual basic, here is my code.

using System;
using System.Collections.Generic;
using System.Text;

namespace CarsDemo.cs
{
    class Cars
    {
        public int idNumber;
        public string make;
        public string model;
        public string color;
        public double cost;

        public int idNumber
        {
            get
            {
                return idNumber;
            }
            set
            {
                idNumber = value;
            }
        }
        public string make
        {
            get
            {
                return make;
            }
            set
            {
                make = value;
            }
        }
        public string model
        {
            get
            {
                return model;
            }
            set
            {
                model = value;
            }
        }
        public string color
        {
            get
            {
                return color;
            }
            set
            {
                color = value;
            }
        }
        public double cost
        {
            get
            {
                return cost;
            }
            set
            {
                cost = value;
            }
        }


        class fleet
        {
            public static void Main()
            {
                Cars first = new Cars();
                Cars second = new Cars();
                Cars third = new Cars();
                Cars forth = new Cars();
                Cars fith = new Cars();
                first.idNumber = 1456;
                first.make = "Bently";
                first.model = "Continettal";
                first.color = "Spruce";
                first.cost = 175990.00;
                second.idNumber = 1859;
                second.make = "Ferrari";
                second.model = "Enzo";
                second.color = "Rosso Corsa";
                second.cost = 680000.00;
                third.idNumber = 1353;
                third.make = "Lamborghini";
                third.model = "Gallardo";
                third.color = "Nero";
                third.cost = 190000.00;
                forth.idNumber = 1986;
                forth.make = "Bugatti";
                forth.model = "Veyron";
                forth.color = "Indigo Blue and Vermilion";
                forth.cost = 1600000.00;
                fith.idNumber = 1990;
                fith.make = "BMW";
                fith.model = "Rolls-Royce Phantom";
                fith.color = "Royal Blue";
                fith.cost = 340000.00;
                Display(first);
                Display(second);
                Display(third);
                Display(forth);
                Display(fith);
            }

            public static void Display(Cars stu)
            {
                Console.WriteLine("{0,5}    {1,-10} {2,6}",
                     stu.IdNumber, stu.make, stu.model, stu.color,
                     stu.cost.ToDouble("F1"));
                Console.ReadLine();
            }
        }
    }
}

if you guys could help out with the code that would be aewsome.

c# is case sensitive

So, if you make a private variable called "myvar" at the top you then cant make a public "myvar" you could have a public "MyVar" though... and thats exactly what its told you

If you're running C# 3.0, you can use this shorthand for the properties; just add {get; set;} after each declaration and so you can totally remove the extra code below:

using System;
using System.Collections.Generic;
using System.Text;

namespace CarsDemo.cs
{
    class Cars
    {
        public int idNumber {get; set;}
        public string make {get; set;}
        public string model {get; set;}
        public string color {get; set;}
        public double cost {get; set;}

        class fleet
        {
            public static void Main()
            {
                Cars first = new Cars();
                Cars second = new Cars();
                Cars third = new Cars();
                Cars forth = new Cars();
                Cars fith = new Cars();
                first.idNumber = 1456;
                first.make = "Bently";
                first.model = "Continettal";
                first.color = "Spruce";
                first.cost = 175990.00;
                second.idNumber = 1859;
                second.make = "Ferrari";
                second.model = "Enzo";
                second.color = "Rosso Corsa";
                second.cost = 680000.00;
                third.idNumber = 1353;
                third.make = "Lamborghini";
                third.model = "Gallardo";
                third.color = "Nero";
                third.cost = 190000.00;
                forth.idNumber = 1986;
                forth.make = "Bugatti";
                forth.model = "Veyron";
                forth.color = "Indigo Blue and Vermilion";
                forth.cost = 1600000.00;
                fith.idNumber = 1990;
                fith.make = "BMW";
                fith.model = "Rolls-Royce Phantom";
                fith.color = "Royal Blue";
                fith.cost = 340000.00;
                Display(first);
                Display(second);
                Display(third);
                Display(forth);
                Display(fith);
            }

            public static void Display(Cars stu)
            {
                Console.WriteLine("{0,5}    {1,-10} {2,6}",
                     stu.IdNumber, stu.make, stu.model, stu.color,
                     stu.cost.ToDouble("F1"));
                Console.ReadLine();
            }
        }
    }
}

Now what LizR said holds firm, and if you don't have C# 3.0, simply rename the variables.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.