Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Recetas.Cap03
- {
- internal class ClaseA { }
- internal class ClaseB { }
- internal class Aplicacion
- {
- public static void Main()
- {
- // Arreglo de instancias Object:
- object[] arregloObject = new object[6];
- // Agrega elementos al arreglo `arregloObject`:
- arregloObject[0] = new ClaseA();
- arregloObject[1] = new ClaseB();
- arregloObject[2] = "Blog xCSw";
- arregloObject[3] = 13;
- arregloObject[4] = 17.9;
- arregloObject[5] = null;
- for (int i = 0; i < arregloObject.Length; ++i)
- {
- // Uso del operador as para convertir a string:
- string cadena = arregloObject[i] as string;
- Console.Write("{0}: ", i.ToString());
- if ( cadena != null)
- {
- Console.WriteLine("'{0}'", cadena);
- }
- else
- {
- Console.WriteLine("El elemento en {0} no es un objeto de string.", i.ToString());
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement