Inconsistent accessibility: parameter type 'PassingCar1Array.CarArray.Car[]' is less accessible than method 'PassingCar1Array.CarArray.DisplayFleet(params PassingCar1Array.CarArray.Car[])'
using
System;namespace
PassingCar1Array{
public class CarArray{
public static void Main(){
Car[] car =
new Car [5]; int x; int enteredId; string enteredMake; string enteredModel; string enteredColor; double enteredValue; for(x = 2; x < car.Length; ++x)car[x] =
new Car();DisplayFleet(car);
}
public static void DisplayFleet (params Car[] Car){
Console.WriteLine("{0,10}{1,10}{2,10}{3,10}{4,10}{5,10}","id","make","model","color","value");
foreach(Car car in Cars){
Console.WriteLine("{0,10}{1,10}{2,10}{3,10}{4,10}{5,10}",Car.GetId(),Car.GetMake(),Car.GetModel(),Car.GetColor(),Car.GetValue());
}
}
class Car{
private int idNumber; private string make; private string model; private string color; private double value; public int GetId(){
return idNumber;}
public string GetMake(){
return make;}
public string GetModel(){
return model;}
public string GetColor(){
return color;}
public double GetValue(){
return value;}
public void SetId(int id){
idNumber = id;
}
public void SetMake(string carMake){
make = carMake;
}
public void SetModel(string carModel){
model = carModel;
}
public void SetColor(string carColor){
color = carColor;
}
public void SetValue(double carValue){
value = carValue;}
}
}
}
herbiePosted May 1, 2007, 10:55 AM
YousefPosted Apr 30, 2007, 5:12 PM
DisplayFleet is a public method, yet it requires the knowledge of "Car" type in it's declaration, hence, Car type needs to be a public class. You currently have Car declared as follows:
class Car {
...
}
Not specifying a public/private keyword in the declaration will automatically default to "private", so "Car" type is a private class type, yet the type needs to be public ally accessible for public methods like DisplayFleet which use it in their signature to work.
This was the long version of the answer. Hope it helps you understand the concept behind. The short version is to change "class Car" to "public class Car" and the compile error will go away.
Good Luck!
Scott LyslePosted Apr 30, 2007, 2:27 PM