martes, 1 de septiembre de 2015

Matrices de objetos.

Programar el siguiente ejemplo y realiza uno propio:

namespace CDCollection
{
    // Define a CD type.
    class CD
    {
        private string album;
        private string artist;
        private int rating;

        public string Album
        {
            get {return album;}
            set {album = value;} 
        }
        public string Artist
        {
            get {return artist;}
            set {artist = value;}
        }
        public int Rating
        { 
            get {return rating;} 
            set {rating = value;} 
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            // Create the array to store the CDs.
            CD[] cdLibrary = new CD[20];

            // Populate the CD library with CD objects.
            for (int i=0; i<20; i++)
            {
                cdLibrary[i] = new CD();
            }

            // Assign details to the first album.
            cdLibrary[0].Album = "See";
            cdLibrary[0].Artist = "The Sharp Band";
            cdLibrary[0].Rating = 10;
        }
    }
}

Fuente: https://msdn.microsoft.com/es-es/library/9ct4ey7x(v=vs.90).aspx

No hay comentarios:

Publicar un comentario