C#C
C#4y ago
9 replies
Petr

✅ Variables from different classes not adding up

Hello my name is Peter and i would like to ask for your help. In my code, i am unable to add variable from one class to variable from another class. I'll show you what i mean:

class Skret : Stvoreni                                 
    {
        private int poskozeniSS { get; set; }
        private int poskozeniU { get; set; }
       

        public Skret() 
        {
            sZdravi = 4 + sObrannaHodnota + sSila;
            sInteligence = 2;
            sSila = 2;
            sObratnost = 2;
            sStesti = 1;
            maManu = false;
            sUtocnaHodnota = 1 + Dyka.poskozeniZbrane;
            sObrannaHodnota = 1 + Latkova.hodnotaBrneni;
        }
}
------------------------------------------------------------------------------------
class Latkova : Zbroje
    {
        public Latkova()
        {
            hodnotaBrneni = 1;
        }
    }
------------------------------------------------------------------------------------
class Program
    {
        static void Main(string[] args)
        {
            Skret skret = new Skret();
            Console.WriteLine(skret.sObrannaHodnota);
        }
        
    }
---------------------------------------------------------------------------------------


So if i try to print the value of
sObrannaHodnota
, it should return 2, since it's 1+1. But unfortunately it returns only 1, as it seems to completely ignore the variable from the other class added to it.
Was this page helpful?