zoukankan      html  css  js  c++  java
  • C#接口实现

    C#可用interface IDrivable实现接口:

    1 /*
    2 Example8_1.cs illustrates interfaces
    3  */
    4
    5  using System;
    6
    7
    8 // define the IDrivable interface
    9 public interface IDrivable
    10 {
    11
    12 // method declarations
    13 void Start();
    14 void Stop();
    15
    16 // property declaration
    17 bool Started
    18 {
    19 get;
    20 }
    21
    22 }
    23
    24
    25 // Car class implements the IDrivable interface
    26 public class Car : IDrivable
    27 {
    28
    29 // declare the underlying field used by the Started property
    30 private bool started = false;
    31
    32 // implement the Start() method
    33 public void Start()
    34 {
    35 Console.WriteLine("car started");
    36 started = true;
    37 }
    38
    39 // implement the Stop() method
    40 public void Stop()
    41 {
    42 Console.WriteLine("car stopped");
    43 started = false;
    44 }
    45
    46 // implement the Started property
    47 public bool Started
    48 {
    49 get
    50 {
    51 return started;
    52 }
    53 }
    54
    55 }
    56
    57
    58 class Example8_1
    59 {
    60
    61 public static void Main()
    62 {
    63
    64 // create a Car object
    65 Car myCar = new Car();
    66
    67 // call myCar.Start()
    68 myCar.Start();
    69 Console.WriteLine("myCar.Started = " + myCar.Started);
    70
    71 // call myCar.Stop()
    72 myCar.Stop();
    73 Console.WriteLine("myCar.Started = " + myCar.Started);
    74
    75 }
    76
    77 }
  • 相关阅读:
    nginx与uwsgi介绍
    Pycharm快捷键
    短信和图片验证码
    linux部署Django脱坑指南
    面试题汇总(七)
    面试题汇总(六)
    面试题汇总(五)
    面试题汇总(四)
    面试题汇总(二)
    iOS Block的本质(四)
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2037020.html
Copyright © 2011-2022 走看看