Why can not I access the methods of a class library?

2

The practice program that I am doing consists of creating an English deck and writing the cards in console (The King of Hearts -for example-), but they do not come out in order, but at random. I have a class library with 2 classes and 2 enum to do this project. But when compiling the code of the main program (image 1) the error marks me. I'm just starting on this, but I can not understand the reason for this error.

Here is the code of my class library .

class Deck
    {
        private Carta[] cartas;
        public Deck()
        {
            cartas = new Carta[52];
            for (int vPalo = 0; vPalo < 4; vPalo++)
            {
                for (int vRango = 0; vRango < 14; vRango++)
                {
                    cartas[vPalo * 13 + vRango - 1] = new Carta((Palo)vPalo, (Rango)vRango);
                }
            }
        }
        public Carta ObtenerCarta(int numeroCarta)
        {
            if (numeroCarta >=0 && numeroCarta <= 52)
            {
                return cartas[numeroCarta];
            }
            else
            {
                throw (new System.ArgumentOutOfRangeException("numeroCarta", numeroCarta, "El numero de cartas debe ser de 52!"));
            }
        }
        public void Shuffle()
        {
            Carta[] nuevoDeck = new Carta[52];
            bool[] asignado = new bool[52];
            Random source = new Random();
            for (int i = 0; i < 52; i++)
            {
                int destCarta = 0;
                bool cartaEncontrada = false;
                while (cartaEncontrada == false)
                {
                    destCarta = source.Next(52);
                    if (asignado[destCarta] == false)
                    {
                        cartaEncontrada = true;
                    }
                }
                asignado[destCarta] = true;
                nuevoDeck[destCarta] = cartas[i];
            }
            nuevoDeck.CopyTo(cartas, 0);
        }
    }
class Carta
    {
        public readonly Palo palo;
        public readonly Rango rango;
        public Carta(Palo unPalo, Rango unRango)
        {
            palo = unPalo;
            rango = unRango;
        }
        private Carta()
        {

        }
        public override string ToString()
        {
            return "El/La " + rango + " de " + palo;
        }
    }
    
asked by Juan Cruz Guzman 29.06.2017 в 21:07
source

4 answers

1

Your problem is solved quickly, definitely all classes are private.

If you add a public ahead, the compilation problems (which you have so far, do not check the whole code) should be fixed.

Neither analyze if it is what corresponds, just focus on your error.

    
answered by 29.06.2017 / 21:13
source
0

By default the classes are Private, you have to specify that they are public classes

    
answered by 29.06.2017 в 21:15
0
  

class Deck

The default classes are private, which means that only the class can access them, instead, if you put:

public class Deck

It means that the class is public, so Any other class can use its methods.

    
answered by 29.06.2017 в 21:17
0

Brother Remember that if you want to invoke a class on a page, your classes should be of type Public apart you should include your class that file and then perform at the beginning of your codehebing

Using ClaseQueHasCreado

If you do not put him as a public, he will never be able to recognize that class.

Greetings.

    
answered by 29.06.2017 в 21:19