ricarditox Posted September 13, 2011 Report Share Posted September 13, 2011 (edited) resulta que quiero guardar datos en un arreglo de objeto, mostrarlos y tambien modificarlos y no se como se hace.. esto es lo que llevo hecho: using System; namespace Registro { class Datos { private int rut; private string nombre; private string fono; private string direccion; public void get(int r, string n, string f, string d) { this.rut = r; this.nombre = n; this.fono = f; this.direccion = d; } public string mostrarNombre() { return nombre; } public int nomstrarRut() { return rut; } public string mostrarFono() { return fono; } public string mostrarDireccion() { return direccion; } public void validar(int ru) { int Digito; int Contador; int Multiplo; int Acumulador; string RutDigito; Contador = 2; Acumulador = 0; while (rut != 0) { Multiplo = (rut % 10) * Contador; Acumulador = Acumulador + Multiplo; rut = rut/10; Contador = Contador + 1; if (Contador == 8) { Contador = 2; } } Digito = 11 - (Acumulador % 11); RutDigito = Digito.ToString().Trim(); if (Digito == 10 ) { RutDigito = "K"; } if (Digito == 11) { RutDigito = "0"; } Console.WriteLine("-{0}",RutDigito); } } class Program { static void Main(string[] args) { Datos obj=new Datos(); int cant,op, i, rut, resp,persona; string nombre, telefono, direccion; Console.WriteLine("Ingrese cantidad de personas : "); cant = int.Parse(Console.ReadLine()); do{ Console.WriteLine("MENU"); Console.WriteLine("1.Insertar\n2.Modificar\n3.Mostrar"); op = int.Parse(Console.ReadLine()); Datos[] arreglodeobjeto = new Datos[cant]; switch(op) { case 1: for (i = 0; i < cant; i++) { Console.WriteLine("Ingrese rut, nombre, telefono y direccion en la persona {0}: ",i+1); rut = int.Parse(Console.ReadLine()); nombre = Console.ReadLine(); telefono = Console.ReadLine(); direccion=Console.ReadLine(); arreglodeobjeto[i] = new Datos(); arreglodeobjeto[i].get(rut, nombre, telefono, direccion); } break; case 2: Console.WriteLine("Ingrese persona que desea modificar : "); persona = int.Parse(Console.ReadLine()); arreglodeobjeto[persona+1] = new Datos(); Console.WriteLine("Ingrese rut, nombre, telefono y direccion en la persona {0}: ",persona); rut = int.Parse(Console.ReadLine()); nombre = Console.ReadLine(); telefono = Console.ReadLine(); direccion = Console.ReadLine(); arreglodeobjeto[persona+1].get(rut, nombre, telefono, direccion); break; case 3: for (i = 0; i < cant; i++) { Console.Write("[{0}]", arreglodeobjeto[i]); } break; } Console.WriteLine("desea repetir operacion? 1.SI / 2.NO"); resp = Int32.Parse(Console.ReadLine()); }while(resp==1); string x = Console.ReadLine(); } } } de antemano gracias :) Edited September 14, 2011 by r_kstro se agrega bbcode code Link to comment Share on other sites More sharing options...
rkstro Posted September 14, 2011 Report Share Posted September 14, 2011 Se mueve a Aplicaciones de escritorio Link to comment Share on other sites More sharing options...
known Posted September 24, 2011 Report Share Posted September 24, 2011 estoy recien aprendiendo c#no estoy seguro..pero quizas las listas genericas pueden ayudarteLee esto ..y ves si es lo que necesitashttp://www.subgurim.net/Articulos/csharp/50/listas-genericas-system-collections-generic-list.aspx Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now