什么是 C# 中的 NZEC 错误以及它在以下代码片段中的位置

本文关键字:代码 片段 位置 中的 NZEC 什么 错误 | 更新日期: 2023-09-27 18:34:57

这是我第一次收到NZEC错误。我不明白这个错误,我只是发现它代表"非零退出代码"。但这是什么意思。当我们收到此错误时。我在其中一个在线编码挑战网站上收到此错误,而不是在Visual Studio中。我真的需要帮助。请检查以下代码片段,我在哪里收到此错误,并请建议我做错了什么。

using System;
using System.Collections.Generic;
using System.Linq;
namespace PractiseConsoleApplication
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            //Get input
            var stringInput = Console.ReadLine();
            var numberOfRooms = Convert.ToInt32(Console.ReadLine());
            var endOfInput = Convert.ToInt32(Console.ReadLine());
            var customers = stringInput.ToArray();
            var hotel = new Hotel(numberOfRooms);
            foreach (var customerName in customers)
            {
                hotel.CheckInCheckoutCustomer(customerName);
            }
            Console.WriteLine(Convert.ToString(hotel.CustomersLeftWithoutStayingInHotel.Count));
        }
    }
    internal class Hotel
    {
        public bool IsRoomAvailable { get; private set; }
        public List<HotelRoom> Rooms { get; private set; }
        public List<char> CustomersLeftWithoutStayingInHotel { get; private set; }
        private Hotel()
        {
            Rooms = new List<HotelRoom>();
            CustomersLeftWithoutStayingInHotel = new List<char>();
        }
        public Hotel(int numberOfRooms)
            : this()
        {
            for (int i = 1; i <= numberOfRooms; i++)
            {
                Rooms.Add(new HotelRoom(i));
            }
        }
        public void CheckInCheckoutCustomer(char customer)
        {
            if (CustomersLeftWithoutStayingInHotel.Any(f => f == customer))
            {
                return;
            }
            var existingCustomer = Rooms.FirstOrDefault(f => f.IsRoomAllocatedToCustomer  && f.CustomerName == customer);
            //Already room allocated to this customer
            if (existingCustomer != null)
            {
                //checkout him
                existingCustomer.CustomerCheckout();
            }
            else
            {
                //Get empty rooms
                var emptyRoom = Rooms.FirstOrDefault(f => f.IsRoomAllocatedToCustomer == false);
                if (emptyRoom != null)
                {
                    emptyRoom.AllocateRoomToCustomer(customer);
                }
                else
                {
                    CustomersLeftWithoutStayingInHotel.Add(customer);
                }
            }
        }
    }
    internal class HotelRoom
    {
        public int RoomNumber { get; private set; }
        public char? CustomerName { get; private set; }
        public HotelRoom(int roomNumber)
        {
            RoomNumber = roomNumber;
            CustomerName = null;
        }
        public bool IsRoomAllocatedToCustomer
        {
            get
            {
                return CustomerName.HasValue;
            }
        }
        public void AllocateRoomToCustomer(char customerDetails)
        {
            CustomerName = customerDetails;
        }
        public void CustomerCheckout()
        {
            CustomerName = null;
        }
    }
    internal class Customer
    {
        public char CustomerName { get; private set; }
        public Customer(char name)
        {
            CustomerName = name;
        }
    }
}

什么是 C# 中的 NZEC 错误以及它在以下代码片段中的位置

正如Tony Hopkinson在评论中所说,main应该返回一个int。
将此语句放在 Main 方法的末尾:

return 0;

这将以零代码退出(因此非零退出代码错误(