access specifier public & internal
In this program class GirlScout's (highlited in yellow) access specifier is internal by default. If access specifier is change into public the program is giving same output. Please tell me the purpose of having internal.
using System;
namespace ConsoleApplication1
{
class DemoScout
{
static void Main(string[] args)
{
GirlScout x = new GirlScout("Rose", 2000, 20.50);
GirlScout y = new GirlScout("Mary", 3000, 45.50);
Console.WriteLine("Name:{0} Troop NO:{1} Owed:${2} Motto:{3}", x.GetName(), x.GetTno(), x.GetOwed(), GirlScout.motto);
Console.WriteLine("Name:{0} Troop NO:{1} Owed:${2} Motto:{3}", y.GetName(), y.GetTno(), y.GetOwed(), GirlScout.motto);
Console.ReadKey();
}
}
}
class GirlScout
{
string name;
int tno;
double owed;
public const string motto = "to obey the Girl Scout law";
public GirlScout(string name, int tno, double owed)
{
this.name = name;
this.tno = tno;
this.owed = owed;
}
public string GetName()
{
return this.name;
}
public int GetTno()
{
return this.tno;
}
public double GetOwed()
{
return this.owed;
}
}
/*
Name:Rose Troop NO:2000 Owed:$20.5 Motto:to obey the Girl Scout law
Name:Mary Troop NO:3000 Owed:$45.5 Motto:to obey the Girl Scout law
*/
Answers (3)
0
An internal class is only accessible from within the same assembly.
If you were writing a class library (.NET dll) and trying to use it from another assembly, then it would not accessible unless you made it public.
It doesn't matter in this program whether your classes are internal or public and so the program compiles in either case and produces the same output.
Accepted 0
A DLL or EXE is an assembly.So "same assembly" means everything that is compiled in Visual Studio as a single project. Things in different projects, even in the same solution, are not in the same assembly .
0
Thank you very much for your explanation. Please explain what is meant by "same assembly"