zoukankan      html  css  js  c++  java
  • C#中接口声明属性,但是提示“接口”中不能有属性。

    C#中接口定义属性如下所示:

    
    
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 
     6 namespace Ch08Ex05
     7 {
     8     abstract  class  HotDrink
     9    {
    10       float  Milk;
    11       float Sugar;
    12      
    13       public int Drink(int x);
    14       public int AddMilk(int x);
    15       public int AddSugar(int x); 
    16 
    17    }    
    18 
    19      public interface ICup
    20   {
    21       int Color;
    22       int Volume;
    23       int Refill(int x);
    24       bool Wash();
    25 
    26    }
    27      class CupOfCoffee:HotDrink,ICup
    28     {
    29         int  BeanType;
    30         
    31         public int Drink(int x)
    32         {
    33            Console.WriteLine("Welcome,Drink a cup of Coffee??
    ");
    34           
    35             return x;
    36         }
    37 
    38       ... ...
    39 }
    40 
    41  class CupOfTea:HotDrink,ICup
    42     {
    43         int  LeafType;
    44         
    45         public int Drink(int x)
    46         {
    47            Console.WriteLine("Welcome,Drink a cup of Tea??
    ");
    48           
    49             return x;
    50         }
    51 
    52       ... ...
    53 }
    54 
    55     class  Program
    56   {
    57       static void Main(string[] args)
    58       {
    59 
    60          CupOfCoffee Coffee=new  CupOfCoffee();
    61          Coffee.Drink(2);
    62          ...
    63 
    64       }
    65 
    66 
    67 
    68   }
    69 
    70 
    71 }

    上面代码提示错误为:

    第21行和第22行,Interfaces cannot contain fields.

  • 相关阅读:
    mysql 日志
    mysql 事务中的锁
    mysql 事务的日志
    mysql 核心事务特性
    mysql 断电导致表打不开解决方案
    mysql 数据库逻辑升级
    mysql innodb存储引擎的表空间
    IDEA常用代码模板
    springcloud-GateWay常用的Predicate
    springcloud-GateWay配置动态路由
  • 原文地址:https://www.cnblogs.com/meihao1989/p/4120828.html
Copyright © 2011-2022 走看看