Forums - C# Corner

Forum guidelines
Maha

Maha

  • 0
  • 0
  • 90.9k

Inconsistent accessibility continue

Aug 21 2013 4:20 PM
http://www.c-sharpcorner.com/Forums/Thread/225889/inconsistent-accessibility.aspx

I wish to know whether it is possible to demonstrate behavioural pattern mentioned of FlavorScoop() method by an example.

Your explanation about using access modifier (14th thread of Inconsistent accessibility)
After this (single module) assembly has been compiled, it could (in theory) be added as a reference to another assembly. If code in the latter assembly wanted to call the FlavorScoop method, it would have problems in doing so because it wouldn't have access to the IceCreamCone class.

The compiler is therefore ensuring that these problems won't arise by flagging it as an error now.

using System;
public class Program
{
public static void Main()
{
IceCreamCone vanilla2 = new IceCreamCone("Vanilla", 2);
IceCreamCone chocolate1 = new IceCreamCone("Chocolate", 1);

FlavorScoop(vanilla2);
FlavorScoop(chocolate1);

Console.ReadKey();
}
public static void FlavorScoop(IceCreamCone icc)
{
Console.WriteLine(icc.GetFlavor() + " flavor" + ", " + icc.GetScoops() + " scoop");
}
}
class IceCreamCone
{
string flavor;
int scoop;

public IceCreamCone(string flavor, int scoop)
{
this.flavor = flavor;
this.scoop = scoop;
}
public string GetFlavor()
{
return flavor;
}
public int GetScoops()
{
return scoop;
}
}


Answers (31)

techbash 2016

SPONSORED BY

C# Corner Chandigarh DevCon16
Chandigarh DevCon16 is a one-day Developer Conference where programmers, technologists, authors, and members meet, demonstrate, plan, and hang out.