472,101 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,101 software developers and data experts.

Inconsistent accessibility

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(ConsoleApplicatio n1.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);
}
}
}

}
*** Sent via Developersdex http://www.developersdex.com ***
Feb 2 '06 #1
3 36914
> 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(ConsoleApplicatio n1.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.

<snip> class Garage

<snip>

Change this to:

public class Garage

Hope this helps.

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Feb 2 '06 #2
AAV <te**********@walla.com> wrote:
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(ConsoleApplicatio n1.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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 2 '06 #3
AAV


thanks for ur replies. it worked.
*** Sent via Developersdex http://www.developersdex.com ***
Feb 2 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Sunit Joshi | last post: by
5 posts views Thread by Andy Fish | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.