ME FIRST GAMES
Menu

games for me and you

C# Tips - Classes

9/9/2020

0 Comments

 
Picture
In C#, everything is associated with classes and objects. A class is simply a "blueprint" for objects, defining their values and behaviors.
​

⭐️ Example
🚗 We define a class Car. It has a value for gas and the ability to move.
🚙 We can instantiate many Cars. Each car is an object with the type of class Car.
✅ Thus, any changes we make in the class Car will be reflected in all the car objects we create.

⭐️ Variables, properties, and methods comprise a class.
📌 Variables hold the state (values) for the class.
📌 Properties usually are just wrappers for variables, preventing us from setting them to an invalid state.
📌 Methods implement behaviors. Your class may have methods to Move, Honk, Stop, Turn, etc.

⭐️ Private vs Public
📌 These special keywords change the access level to certain variables, properties, and methods.
🕵️‍♀️ Private - The type or member can only be accessed by code in the same class (or struct).
💁‍♀️ Public - The type or member can be accessed by any other code.
✅ Use these keywords to create an interface for your Class. So the inner details are all handled inside and external code won't change variables or call methods that put your class into an invalid state.

⭐️ Here are some interesting features we'll look up in the future. I suggest your research them beforehand.
📌 Classes may inherit behavior and values from another class. e.g. Horse class inherits from Animal class.
📌 Classes can be defined as static. Meaning, the class is the one-and-only one instance of itself.
📌 Classes have more access levels: Protected, Internal, and Protected Internal.
📌 Classes are always allocated on the Heap.



0 Comments



Leave a Reply.

    Picture
    Me First Games is an independent game studio dedicated to creating unique and bizarre video games.
    GAMES HERE

    Red Matter

    Star Impact is an upcoming adventure platformer coming to PC, Mac, and Linux.

    Archives

    April 2021
    February 2021
    December 2020
    November 2020
    October 2020
    September 2020
    August 2020
    July 2020
    June 2020
    May 2020
    April 2019
    March 2019
    December 2018
    April 2018

    Categories

    All

    RSS Feed

Copyright (c) 2020 Me First LLC
  • STU the First AI
  • Blog
  • Contact
  • Unity Tools
    • Hierarchy Comments
  • STU the First AI
  • Blog
  • Contact
  • Unity Tools
    • Hierarchy Comments