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.

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

     

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

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

  • 相关阅读:
    053467
    053466
    053465
    NC201613 Jelly
    NC14608 after与迷宫
    NC14572 走出迷宫
    340. 通信线路
    1135. 新年好
    903. 昂贵的聘礼
    P5767 [NOI1997]最优乘车
  • 原文地址:https://www.cnblogs.com/luvianlan/p/4394334.html
Copyright © 2011-2022 走看看