接口的C#问题中的代码契约

时间:2019-04-23 09:15:54

标签: c# interface code-contracts

我试图在我的c#程序中创建一个接口并使用代码协定,但是该程序无法生成,并且在控制台上出现此错误。

    interface Parking
    {

        int MaxParkingSpaces { get; set; }
        int AvailableSpaces { get; set; }
        int MaxConferencesinSeason { get; set; }

        bool reserveSpace(int conferenceID, int parkingID, string Customer);
        bool buySpace(int conferenceID, int parkingID, string Customer);
        bool returnSpace(int conferenceID, int parkingID, string Customer);
        bool cancelReservation(int conferenceID, int parkingID);
        string checkAvailability(int conferenceID);
        bool checkCustomer(int conferenceID, int parkingID, string Customer);
    }

  class CarPark : Parking
    {
        public Conferences[] conferencesArray { get; set; }
        public int MaxParkingSpaces { get; set; }//Total number of space which a conference can have
        public int MaxConferencesinSeason { get; set; } //Fixed number of conferences per season
        public int AvailableSpaces { get; set; }

        public CarPark()
        {
            MaxParkingSpaces = 150;
            MaxConferencesinSeason = 10;
            AvailableSpaces = MaxParkingSpaces - 3;
            conferencesArray = new Conferences[MaxConferencesinSeason];
            for (int i = 0; i < MaxConferencesinSeason; i++)
            {
                conferencesArray[i] = new Conferences()
                {
                    conferenceId = i,
                    ParkingArray = new ParkingSpaces[MaxParkingSpaces]
                };

                for (int j = 0; j < MaxParkingSpaces; j++)
                {
                    conferencesArray[i].ParkingArray[j] = new ParkingSpaces()
                    {
                        parkingID = j,
                        parkingIsReserved = false,
                        parkingisReservedByCustomer =false,
                        parkingIsPurchased = false

                    };
                }
            }
        }
        public bool reserveSpace (int conferenceID, int parkingID, string Customer)
        {
            Contract.Requires(conferencesArray[conferenceID].ParkingArray[parkingID].parkingIsReserved);

            return true;


        }
  

警告CC1033:方法'CO3401Part2.Program + CarPark.reserveSpace(System.Int32,System.Int32,System.String)'实现接口方法'CO3401Part2.Program + Parking.reserveSpace(System.Int32,System.Int32,System .String)”,因此无法添加Requires。

0 个答案:

没有答案