如何从if-else语句中另一个类的内部获取值?

时间:2018-10-15 17:07:57

标签: c# class variables if-statement

当我从另一个类调用dnanumber变量时,在控制台中似乎是0。我该如何解决这个问题?

class DNAgenerator
    {



        public int dnanumber;



        public int dna;
        public int dna2;
        public int dna3;
        public int dna4;



        public void generetor()
        {

            Random user = new Random();

            dna = user.Next(1,41);
            dna2 = user.Next(1,41);
            dna3 = user.Next(1, 41);
            dna4 = user.Next(1, 41);

            Random nukleodite = new Random();



            if (dna == nukleodite.Next(1,11))
            {            
                dnanumber = 65;
            }

              else if(dna== nukleodite.Next(11, 21))
            {

                dnanumber = 67;
             }
             else if (dna == nukleodite.Next(21, 31))
                {

                dnanumber = 71;
             }
           else if(dna == nukleodite.Next(31,41))
            {

                dnanumber = 84;
            }


            //   dna2   

            if (dna2 == nukleodite.Next(1, 11))
            {
                dnanumber = 65;
            }

            else if (dna2 == nukleodite.Next(11, 21))
            {
                dnanumber = 67;
            }
            else if (dna2 == nukleodite.Next(21, 31))
            {
                dnanumber = 71;
            }
            else if (dna2 == nukleodite.Next(31, 41))
            {
                dnanumber = 84;
            }


            //dna3


            if (dna3 == nukleodite.Next(1, 11))
            {

            }

            else if (dna3 == nukleodite.Next(11, 21))
            {

            }
            else if (dna3 == nukleodite.Next(21, 31))
            {

            }
            else if (dna3 == nukleodite.Next(31, 41))
            {

            }


            //dna4

            if (dna4 == nukleodite.Next(1, 11))
            {

            }

            else if (dna4 == nukleodite.Next(11, 21))
            {

            }
            else if (dna4 == nukleodite.Next(21, 31))
            {

            }
            else if (dna4 == nukleodite.Next(31, 41))
            {

            }

        }
   }


static void Main(string[] args)
        {




            DNAgenerator user = new DNAgenerator();




            user.generetor();







            Console.WriteLine(user.dna.ToString() + " " +user.dna2.ToString() + " " + user.dna3.ToString() + " " + user.dna4.ToString() );




            Console.ReadKey();
        }

0 个答案:

没有答案