In the this program if you write public in front of
static void Display(Employee num) program is not executing. Please tell me the reason. Problem is highlighted.
But internal access modifier instead of public in the program is executing.
using System;
public class CreateEmployee
{
public static void Main()
{
Employee myAssistant = new Employee();
myAssistant.SetId(345);
Display(myAssistant);
Console.ReadKey();
}
static void Display(Employee num)
{
Console.WriteLine("ID # is {0}", num.GetId());
}
}
internal class Employee
{
private int idNumber;
public int GetId()
{
return idNumber;
}
public void SetId(int id)
{
idNumber = id;
}
}
// ID # is 345
Loading

Iftikar HussainRank #423 · 5.9K reputationPosted Jul 12, 2013, 10:34 PM EDT
The reason is - Internal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current assembly. In other words, any member with internal access specifier can be accessed from any class or method defined within the application in which the member is defined. You can refer below link for more details.
http://msdn.microsoft.com/en-us/library/ba0a1yw2(v=vs.80).aspx
http://msdn.microsoft.com/en-us/library/ms173121.aspx
Regards,
Iftikar
VulpesRank #55 · 29.2K reputationPosted Jul 13, 2013, 12:06 AM EDT
Posted Jul 13, 2013, 2:31 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 13, 2013, 2:48 AM EDT
'internal' means accessible within the type itself or within the current assembly.
Posted Jul 13, 2013, 3:03 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 13, 2013, 3:21 AM EDT
Inside a public method any public, internal or protected internal type or member within the same assembly can be accessed. So can any private or protected member (including inherited protected members) within the same type.
Posted Jul 13, 2013, 6:37 AM EDT