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??\n");
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??\n");
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.

 

转载于:https://www.cnblogs.com/meihao1989/p/4120828.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值