locked
what is wrong in ths code RRS feed

  • Question

  • User569149469 posted
    using System;
    using System.Collections.Generic;
    
    public class DocumentStore
    {
        private  readonly List<string> documents = new List<string>();
        private  readonly int capacity;
    
        public DocumentStore(int capacity)
        {
            capacity = capacity;
        }
    
        public  int Capacity { get { return this.capacity; } }
    
        public IEnumerable<string> Documents { get { return documents; } }
    
        public void AddDocument(string document)
        {
            if (documents.Count > capacity)
                throw new InvalidOperationException();
    
            documents.Add(document);
        }
    
        public override string ToString()
        {
            return String.Format("Document store: {0}/{1}", documents.Count, capacity);
        }
    }
    
    public class Program
    {
        public static void Main(string[] args)
        {
            DocumentStore documentStore = new DocumentStore(2);
            documentStore.AddDocument("item");
            Console.WriteLine(documentStore);
        }
    }

    Sunday, August 19, 2018 9:40 PM

All replies