Inconsistent accessibility

A

AAV

what is wrong with the code i get
'Error 1 Inconsistent accessibility: parameter type
'ConsoleApplication1.Garage.CarDelegate' is less accessible than method
'ConsoleApplication1.Car.process(ConsoleApplication1.Garage.CarDelegate)
' E:\VS2005_Study\Delegates.cs 49 23 ConsoleApplication1
'



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

namespace ConsoleApplication1
{


public class Car
{

private String CName;
public bool rotateTires, washCar;
private int speed;
public String name {
get{return CName;}
set{CName=name;}
}
public Car(String name, int s,bool Tire, bool Wash)
{
CName = name;
rotateTires = Tire;
washCar = Wash;
speed = s;
}
public void accelerate(int delta)
{

if (speed > 100)
return;
speed += delta;
if (speed <= 80)
{
Garage.caution(CName + " Going");
}
else if (speed > 80 && speed < 100)
{
Garage.caution("hi " + CName + " take Caution");

}
else if (speed > 100)
{
Garage.expiry("Oh man " + CName + " is Dead");
}

}

public void process(Garage.CarDelegate c)
{
c(this);
}

}

class Garage
{
public delegate void cautionDelegate(String msg);
public delegate void expiryDelegate(String msg);
public delegate void CarDelegate(Car c);
public static cautionDelegate caution;
public static expiryDelegate expiry;
public static CarDelegate card;



public static void Main() {
System.Collections.ArrayList a = new
System.Collections.ArrayList();
caution = new Garage.cautionDelegate(cautionfunction);
expiry = new Garage.expiryDelegate(cautionfunction);
a.Add(new Car("0",10, true, true));
a.Add(new Car("1", 20,true, false ));
a.Add(new Car("2", 30,false , true));
a.Add( new Car("3", 40,false , false ));
for (int i = 0; i < 5; i++)
{
foreach (Car c in a)
c.accelerate(20);
}

card = new CarDelegate(new ServiceCenter().rotatetires);
foreach(Car c in a)
c.process(card);
card = new Car.CarDelegate(new ServiceCenter().cleancar);
foreach(Car c in a)
c.process(card);
Console.ReadLine();

}


public static void cautionfunction(String msg)
{
Console.WriteLine(msg);
}

}

class ServiceCenter
{
public void rotatetires(Car c)
{
if (c.rotateTires == true)
{
Console.WriteLine("Roted Car " + c.name);
}
}
public void cleancar(Car c)
{
if (c.washCar == true)
{
Console.WriteLine("Cleaned Car" + c.name);
}
}
}

}
 
?

=?iso-8859-1?Q?Lasse=20V=e5gs=e6ther=20Karlsen?=

what is wrong with the code i get
'Error 1 Inconsistent accessibility: parameter type
'ConsoleApplication1.Garage.CarDelegate' is less accessible than
method
'ConsoleApplication1.Car.process(ConsoleApplication1.Garage.CarDelegat
e)
' E:\VS2005_Study\Delegates.cs 49 23 ConsoleApplication1
'

Well, the delegate isn't available to code outside your assembly. In your
particular project it might not be a problem but the C# compiler won't let
you do it.

To solve it, make the class Garage public as well.

class Garage
<snip>

Change this to:

public class Garage

Hope this helps.
 
J

Jon Skeet [C# MVP]

AAV said:
what is wrong with the code i get
'Error 1 Inconsistent accessibility: parameter type
'ConsoleApplication1.Garage.CarDelegate' is less accessible than method
'ConsoleApplication1.Car.process(ConsoleApplication1.Garage.CarDelegate)
' E:\VS2005_Study\Delegates.cs 49 23 ConsoleApplication1
'

The Garage class is internal, so even though you've marked the
CarDelegate delegate as public, anything outside the assembly still
won't be able to see it, which means they won't be able to understand
the parameter to Car.process.

Make the Garage class public and it should be fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top