zoukankan      html  css  js  c++  java
  • C# 第四次作业

    这节课老师首先介绍了structs 和class 的区别

    1. Structs are value types.
    2. Structs can be instantiated without using a new operator. Structs can declare constructors, but they must take parameters, can not declare default constructor-compiler will provide one & no Destructor.
    3. A struct cannot inherit from another struct or class, and it cannot be the base of a class. It only inherit from the base class Object. A struct can implement interfaces.
    4. Within a struct declaration, fields cannot be initialized unless they are declared as const or static.

    定义strcts的格式如下▼

    然后我自己试了一下定义struct▼

    然后老师为我们讲解了interface:

    1. An interface is a contract that guarantees to a client how a class or struct will behave.

    2. When a class implements an interface, it tells any potential client “I guarantee I’ll support all the methods, properties, events, and indexers of the named interface.”

    3. These contracts are made manifest(表明) using the interface keyword, which declares a reference type that encapsulates the contract.

    定义interface的格式如下▼

    我也尝试着自己定义了一个interface▼

    之后老师辨别了Abstract Class, Interface 和 Mix-Ins

    1. An interface offers an alternative to an abstract class for creating contracts among classes and their clients.

    2. The difference is that abstract classes serve as the top of an inheritance hierarchy, where as interfaces may add their contract to numerous inheritance trees.

    然后我创建了一个类去继承这个接口▼

     

    而如果是多个接口直接罗列在后面就好了,不过值得注意的是每个接口在继承时都要被定义。

    而我们也可以在接口与接口中继承,这个比较宽泛,可以一对一也可以多对一。

  • 相关阅读:
    Python常见的几种算法
    Python的八种数据类型
    网络协议
    Python基本知识
    Python简介
    Windows10 java环境配置
    linux 为动态分配的Virtualbox虚拟硬盘扩容
    ubuntu 18.04.1安装hadoop3.1.2
    linux 安装virtualbox5.2
    这是写给我自己看的!!
  • 原文地址:https://www.cnblogs.com/luvianlan/p/4394334.html
Copyright © 2011-2022 走看看