I need someone to help me understanding this bit of c# code:
public Teacher[] Teachers { get; set; }
I can see this is an array but is it ok to use get, set here instead of :
public Teacher[] Teachers = new Teacher[4];
I need someone to help me understanding this bit of c# code:
public Teacher[] Teachers { get; set; }
I can see this is an array but is it ok to use get, set here instead of :
public Teacher[] Teachers = new Teacher[4];
 
    
     
    
    public Teacher[] Teachers { get; set; }
This creates a property called Teachers of type Teacher[].
public Teacher[] Teachers = new Teacher[4];
This creates a field called Teachers of type Teacher[] and initializes it will a length of 4.
You can initialize a property in the classes constructor:
public class TestClass
{
    public Teacher[] Teachers { get; set; }
    public TestClass()
    {
       Teachers = new Teacher[4];
    }
}
Read here about the difference between a property and a field.
 
    
    