Get count of credit cards that are expired Below is a sample implementation for getting the expired credit cards in the credit card list.I wrote a property and initialized it in the constructor. Need an opinion on if this is a proper way to implement it.

   public class User
    {
        private readonly List&lt;CreditCard&gt; creditCards;

        public int CountOfCreditCards
        {
            get
            {
                return counter;
            }
        }

        private static int counter;

        private User()
        {
            creditCards = new List&lt;CreditCard&gt;();
            counter = GetCountOfExpiredCreditCards();
        }

        public int GetCountOfExpiredCreditCards()
        {
            return creditCards.Count(x =&gt; x.ExpirationMonth &lt;= DateTime.Now.Month);
        }
    }
If a class has one or more private constructors and no public constructors, other classes (except nested classes) cannot create instances of this class.


https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/private-constructors

Make your constructor public.

There is an obvious bug in GetCountOfExpiredCreditCards  A card that expires in 01/19(January, 2019) will show up as expired if checked today.  Check for both year and month.