Is it wrong to store data in the library?

I am in the middle of creating a new library, and since I was building it, something seemed a little strange. Here is the code:

namespace traditional_poker
{
    public class poker
    {
       public class hand
        {
           public String Name
            {
                get; set;
            }
           public String[] cards
            {
                get; set;
            }

        }

        List<hand> players;

        public void AddPlayer(String name)
        {
            hand newHand = new hand();
            newHand.Name = name;
            players.Add(newHand);
        }
    }
}

I have it List<hand> playersinside the library itself, which means the library stores data (albeit temporarily).

Is this a bad practice?

Is there a better way to do this?

Or is this how I do it completely legal?

+4
source share
2 answers

, . , . , (, ..)

namespace traditional_poker
{
    public class poker
    {
       public class hand // use PascalCaseNamingConvention
        {
           public String Name
            {
                get; set;
            }
           public String[] cards // use PascalCaseNamingConvention
            {
                get; set;
            }

        }

        List<hand> players;

        public void AddPlayer(String name)
        {
            hand newHand = new hand();
            newHand.Name = name;
            players.Add(newHand); //null reference exception here! you should initialize players
        }
    }
}
+3

.

, , . , , .

, .

+2

Source: https://habr.com/ru/post/1615911/


All Articles