I'm still finding my feet with C# and have a quick question that has been bugging me for a while.
Say I write a class and define a property as follows:-
public class Employee
{
string FirstName {get; set;}
}
class Program
{
private static object GetTheEmployee()
{
return new Employee{ FirstName = "Joe" }
}
}
Why is use of FirstName within the GetTheEmployee method inaccessible, but when I change the FirstName 'string' variable in the Employee class to 'public string' instead, it is accessible from the Program class.
I would have thought that if I declare the class' access modifier as public, then all variables within in the class will also be public by default?