using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// Nested namespace to avoid collision between examples 17 and 18
namespace FieldsAndConstructors.Example18
{
    // Example 3-18
    public class ItemWithId
    {
        private static int _lastId;
        private int _id;
        private string _name;

        public ItemWithId()
            : this(null)
        {
        }

        public ItemWithId(string name)
            : this(name, ++_lastId)
        {
        }

        private ItemWithId(string name, int id)
        {
            _name = name;
            _id = id;
        }
    }
}
