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
*/
Loading
VulpesPosted Jul 20, 2012, 10:35 AM
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.
Santhosh Kumar JayaramanPosted Jul 20, 2012, 11:05 AM
Posted Jul 20, 2012, 10:58 AM