Samenvatting van leerkracht

Cards (29)

  • What are properties in C#?
    Members of classes, structures, and interfaces
  • What are member variables in C#?
    Fields of classes, structures, and interfaces
  • How do properties extend fields in C#?
    They expose public access while hiding logic
  • How are properties accessed in C#?
    Using the same syntax as fields
  • What does the 'get' accessor do in a property?
    Returns the value of a private field
  • What does the 'set' accessor do in a property?
    Assigns a value to a private field
  • What is the purpose of the 'Main' method in C#?
    Entry point for the application
  • How can properties be implemented as expression-bodied members?
    Using the => symbol followed by an expression
  • When should constructor parameters be used in C#?
    For required properties during object construction
  • How would you define an auto property with a private setter?
    public string Name { get; private set; }
  • What are property initializers used for?
    For additional configuration after construction
  • How would you create a person object with optional address?
    Person personObject = new Person("John Doe", 24) { Address = "42 Adams Street" };
  • What does the 'const' keyword do in C#?
    Makes a field constant and unmodifiable
  • When must constants be initialized?
    At the time of declaration
  • What is a compile-time constant?
    A const field initialized at declaration
  • What does the 'readonly' keyword allow in C#?
    Field initialization at declaration or constructor
  • How can a readonly field be modified?
    Only in the constructor of the class
  • What does the 'static' keyword indicate?
    Members shared by all class objects
  • What can static members access?
    Only static members of the same class
  • What happens if a class is declared static?
    All members of the class must be static
  • When should you use 'const' in C#?
    For simple values that don't change
  • When should you use 'readonly' in C#?
    For variables that shouldn't change after initialization
  • What does the 'typeof()' function do?
    Gets the type at compile time
  • What does the 'GetType()' function do?
    Gets the runtime type of an instance
  • What does the 'is' operator do?
    Checks if an instance is in the inheritance tree
  • How do you cast an object to a specific type?
    Using (Type) object syntax
  • How do you implement polymorphism in C#?
    By assigning a derived class to a base class reference
  • What does the 'as' operator do in C#?
    Attempts to cast an object to a type
  • How can inline casting be done in C# 7+?
    Using the 'is' operator with assignment