This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.

👉 About the author

As we all know, life is a long process of constantly overcoming difficulties and reflecting on progress. In this process, there will be a lot of questions and thoughts about life, so I decided to share my thoughts, experiences and stories to find resonance!!

Focus on Android/Unity and various game development tips, as well as various resource sharing (websites, tools, materials, source code, games, etc.)

Welcome to pay attention to the public account [Mr. Empty name] for more resources and communication!

👉 Practice

😜 class/function

Classes are still class qualifiers. You can specify access rules for classes and members before class. If not, classes are internal by default, and member access is private. Example: The public class name {} function has constructors and parameterized functions, as well as a destructor, which is a special member function. It’s a new thing to remember. Destructors are prefixed with ~, do not require any modifiers, return no value, take no arguments, and cannot be inherited or overloaded. It is lazy. Garbage collection will be collected at the appropriate time, such as when memory is running low, when the program is closed, etc. This is similar to onDestory on Android, but also has a GC method to enforce collection.

😜 Inheritance/multiple inheritance

Inheritance is one of the most important concepts in object-oriented design. A class inherits from another class. For example: Class A{} Class B:A{} B inherits from A. (Derived and base classes, subclasses and superclasses). B has access to A, which means that the subclass gets the property of its parent, but the parent doesn’t get the property of the subclass. C# does not support multiple inheritance, I consulted C++ colleagues, C++ supports multiple inheritance.

😜 polymorphism

One of the core functions of object-oriented programs is the ability to have multiple representations of the same behavior. C# and Java are both object oriented and their polymorphisms are basically the same. Many advantages:

  1. Eliminate coupling between types
  2. With scalability, enhance flexibility
  3. Interface, simple implementation

C# contains static and dynamic polymorphism. Static polymorphism also includes function overloading and operator overloading. Function overloading: Multiple definitions of the same function name. Function argument type or number of different to implement. Such as: Int test(int num1){} int test(int num1,int num2){} int test(int num1,string num1){} Dynamic overloading is an abstract class created with abstract, and another similar implementation of virtual methods modified with the keyword virtual. The sample

namespace Test
{
   abstract class Shape
   {
       abstract public int area();
   }
   class Rectangle:  Shape
   {
      private int length;
      private int width;
      public Rectangle( int a=0.int b=0)
      {
         length = a;
         width = b;
      }
	  // Take note of override
      public override int area ()
      {
         Console.WriteLine("Rectangle class size:");
         return(width * length); }}class RectangleTester
   {
      static void Main(string[] args)
      {
         Rectangle r = new Rectangle(10.7);
         double a = r.area();
         Console.WriteLine("Area: {0}",a); Console.ReadKey(); }}}// Examples of virtual methods
namespace Test
{
   class Shape
   {
      protected int width, height;
      public Shape( int a=0.int b=0)
      {
         width = a;
         height = b;
      }
      // Keyword virtual
      public virtual int area()
      {
         Console.WriteLine("Area of parent class:");
         return 0; }}class Rectangle: Shape
   {
      public Rectangle( int a=0.int b=0) :base(a, b){}public override int area ()
      {
         Console.WriteLine("Rectangle class size:");
         return(width * height); }}class Triangle: Shape
   {
      public Triangle(int a = 0.int b = 0) :base(a, b){}public override int area()
      {
         Console.WriteLine("Triangle class area:");
         return (width * height / 2); }}class Tester
   {
     
      static void Main(string[] args)
      {
         Rectangle r = new Rectangle(10.7);
         Triangle t = new Triangle(10.5); c. area (); c. area (); Console.ReadKey(); }}}Copy the code

😜 interface

Interfaces are declared using the interface keyword, similar to class declarations, which are of type public by default. When there are multiple classes, multiple classes have multiple same methods, use interfaces to achieve easy management, and not lost. Basically the same with Java. Example:

interface ITestInterface
{
    void TestInterfaceMethod();
}
public class Test : ITestInterface{
public void TestInterfaceMethod(){}}Copy the code

👉 other

📢 author: Kom and Kom in Kom

📢 reprint instructions – be sure to specify the source: Zhim Granular’s personal home page – column – Nuggets (juejin. Cn)

📢 welcome to like 👍 collect 🌟 message 📝

[Welcome to discuss in the comments section. The nuggets will draw 100 nuggets in the comments section after the diggnation project. See the article for details.]