简体   繁体   中英

What is NZEC error in C# and where it is in following code snippet

This is the first time I am getting NZEC error. I don't understand this error, I just found that it stands for "Non Zero Exit Code". But what does this means. When we get this error. I am getting this error on one of online coding challenge websites and not in Visual Studio. I am real need of help. Please check following code snippet where I am getting this error and please suggest what I am doing wrong.

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;
        }
    }
}

as Tony Hopkinson says in the comments, main should return an int.
place this statement in the end of main method:

return 0;

this will exit with zero code(thus the Non Zero Exit Code error)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM