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.

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

     

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

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

  • 相关阅读:
    操作系统(一) 操作系统的概念
    数据结构(六) 排序
    数据结构(五) 查找和哈希表
    数据结构(三) 树和二叉树,以及Huffman树
    数据库简述(以MySQL为例)
    Java中的UDP应用
    Java线程池应用
    Java定时器应用
    JavaSE项目之聊天室swing版
    用LinkedList集合演示栈和队列的操作
  • 原文地址:https://www.cnblogs.com/luvianlan/p/4394334.html
Copyright © 2011-2022 走看看