C# 102 - Lecture 1 Notes

Jul 7, 2024

C# 102 - Lecture 1: Introduction and Key Concepts

Introduction

  • Welcome to C# 102: Continuation from C# 101.
  • Instructors: Main instructor Mr. Nelson Lokay. Jason Busby will provide additional commentary. TA: Gavin Woodlock.
  • Course Prerequisites: C# 101 is necessary before taking this course.
  • Course Agenda: Mixture of 102, 103, and 106 topics.
  • Office Hours: Wednesdays, rotating times to accommodate different time zones. Available for one-on-one help.
  • Attendance Credit: Join Buzznet at buzznet.3dbuzz.com for attendance credit. Participating students need to click the 'Participate' button.
  • Calendar and Homework: Live class calendar for registration, passwords (posted 5 minutes before class), and homework (posted within an hour after class ends). Videos available for member sponsors.

Course Focus

  • Main Objective: Understanding object-oriented programming using C#.
  • Key Topics:
    • Objects and classes.
    • Inheritance, interfaces, polymorphism, encapsulation.
    • Utilizing .NET BCL (Base Class Library).
    • File I/O, collections, iterators, and IDisposable.
    • Design discussions: SOLID principles.
    • Practical example: Building a text-based RPG game.

Review from C# 101

  • Variables: Declaration, initialization, and scope.
  • Conditionals: If, else, and else if statements.
  • Loops: While loops, for loops, and for each loops.
  • Methods: Definition, parameters, return types, and importance of grouping functionalities.
  • Classes: Creating classes, properties, methods, constructors, and instantiation.
  • Static Members: Definition and use cases for static fields and methods.
  • Class Inheritance: Creating subclasses, understanding base classes, overriding methods.
  • Polymorphism: Using derived classes in place of base classes, understanding virtual and override keywords.
  • Reflection: Brief mention of gathering type information at runtime.

In-depth: Inheritance & Virtual Members

  • Inheritance: Using the : BaseClass syntax. Concept of base and derived classes.
  • Virtual Members: Defining methods with the virtual keyword to allow overriding. Using the override keyword in derived classes.
  • Abstract Classes and Methods: Defining abstract classes and methods to create base templates that cannot be instantiated directly.
  • Application: Example with Item, Chair, Potion, and Gun classes to illustrate polymorphism and methods overriding.

Practical Exercise and Q&A

  • Constructors: Utilizing base constructors in child classes using the base keyword.
  • More examples: Given on abstract classes and use cases in polymorphism.
  • Detailed Q&A: Addressing various student questions on inheritance, method overriding, constructor chaining, and type references.

Homework

  • Assignment:

    • Create a Pet class with abstract functionalities (at least three methods).
    • Implement at least one method that takes parameters and one returning a value.
    • Include a constructor taking a name with read-only property.
    • Create four concrete implementations of the Pet class.
    • Allow users to enter zero-to-many pets and store them in a list.
    • Enable users to perform operations on the pets, collecting arguments as required.
  • Submission:

    • Follow submission guidelines provided in the member sponsor lounge.

Conclusion

  • Next Steps: Review the material, attend office hours for clarity, complete homework, and prepare for the next lecture covering BCL and state machines.