Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
So i want to reset all my values of a class i use "new Class()" for that however i dont want to reset a few.

The class is
C#
class Settings
    {
        public static bool Exit { get; set; }

        public static int Count { get; set; }
        public static int DealersCount { get; set; }
        public static int Bet { get; set; }
        public static int RemainingChips { get; set; }
        public static string FirstCard { get; set; }
        public static string SecondCard { get; set; }
        public static int CardA { get; set; }
        public static int FirstCount { get; set; }
        public static int SecondCount { get; set; }
        public static int CardNo { get; set; }
        public static string CardData { get; set; }
        public static int Picture { get; set; }
        public static bool AceTrue { get; set; }
        public static bool TenTrue { get; set; }
        public static Action Act { get; set; }
        public static bool Bust { get; set; }

        public static bool Bust1 { get; set; }
        public static bool Bust2 { get; set; }
        public static bool DealerBust { get; set; }
        public static bool PlayerStand { get; set; }
        public static int FinalCount { get; set; }
        public static int Final1Count { get; set; }
        public static int Final2Count { get; set; }
        public static int DFinalCount { get; set; }

        public static int DFinal1Count { get; set; }
        public static int DFinal2Count { get; set; }
        public static int HitCount { get; set; }
        public static bool Hit { get; set; }





        public Settings()
        {
            DFinal1Count = 0;
            DFinal2Count = 0;
            Bust = false;
            Hit = true;
            Final1Count = 0;
            Final2Count = 0;
            Exit = false;
            Count = 0;
            DealersCount = 0;
            Bet = 0;
            FirstCard = "";
            SecondCard = "";
            FirstCount = 0;
            SecondCount = 0;
            CardNo = 0;
            CardData = "";
            Picture = 0;
            AceTrue = false;
            TenTrue = false;
            Act = Action.deal;
            CardA = 0;
            Bust1 = false;
            Bust2 = false;

            DealerBust = false;
            PlayerStand = false;
        }


    }

I dont want to reset Final1count and final2count, bet, remaining bet right now but reset it later

What I have tried:

i tried googling, lead to
c# - How do I reinitialize or reset the properties of a class? - Stack Overflow[^]

Didnt answer my question
Posted
Updated 30-May-20 14:05pm
v3

1 solution

This does not make any sense to create a new instance since all your properties are static. This means that they are shared by all instances of the class.

To "reset" them, you could create a static method assigning whatever values to whatever property you need to reset.

On the other hand, you could make your properties non-static (i.e., instance properties), and create a constructor accepting a Settings instance which you would use to initialize the new instance.

All of this makes me think that you have skipped some important chapters about OOP/C#; you should search for basic tutorials and study them formally.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900