Вы находитесь на странице: 1из 3

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace datos
{
class Program
{

String[] arreglo1;
int posicion = 0;
int n;
static void Main(string[] args)
{
MiExcepcion oe = new MiExcepcion();
Program ob1 = new Program();
Program t = new Program();
ob1.arreglo1 = new String[t.devn()];
int op = 0;
Program ob = new Program();
do
{
Console.Clear();
Console.WriteLine("0) Fijar el tamao del arreglo");
Console.WriteLine("1) llenar el arreglo");
Console.WriteLine("2) mostrar los datos");
Console.WriteLine("3) salir");
Console.WriteLine("\n sellecciona una opcion: ");
try
{
op = Convert.ToInt32(Console.ReadLine());
}
catch (IOException) { throw oe; }
switch (op)
{
case 0:
ob.Leer_Tamao();
Console.ReadKey();
break;
case 1:

ob.llenar_arreglo();
break;
case 2:
ob.Mostrar_Datos();
Console.ReadKey();
break;
case 3:
Console.WriteLine("hasta la vista");
Console.ReadKey();
break;
default:
Console.WriteLine("escoja una opcion valida");
break;
}
}
while (op != 3);
}
// termino main
public void Leer_Tamao()
{
int m = 0;
do
{
try
{
Console.WriteLine("de que tamao quiere su arreglo");
n = Convert.ToInt32(Console.ReadLine());
arreglo1 = new String[n];
m++;
}

catch (IOException oe) { throw oe; }


}
while (n ==0);

}
public int devn()
{
return n;
}
public void llenar_arreglo()
{
if (posicion >= devn())
{
Console.WriteLine("el arreglo esta lleno");
Console.ReadKey();
}
else
{
Program p = new Program();

Console.WriteLine("escriba las palabras");


String valor = Convert.ToString(Console.ReadLine());
arreglo1[posicion] = valor;
posicion++;
// inicio texto
using (StreamWriter sw = File.CreateText("Tamao-Arreglo.txt"))
{
sw.WriteLine(n);
sw.Close();
}
// fin texto
}
}
public void Mostrar_Datos()
{
if (posicion == 0)
{
Console.WriteLine("el arreglo esta vacio");
}
else
{
Console.WriteLine("estos son los datos: ");
for (int n = 0; n < posicion; n++)
{
Console.WriteLine("" + arreglo1[n]);
// inicio
using (StreamWriter sw = File.CreateText("Arreglo1.txt"))
{
sw.WriteLine(arreglo1[n]);
sw.Close();
}
// fin
}
}
}
}
}

class MiExcepcion:Exception
{
private String descripcion;
public MiExcepcion()
{
descripcion = "solamente numeros";
}
}

Вам также может понравиться