Freddy Abreu

Freddy Abreu

  • NA
  • 40
  • 7.6k

Delete a data in C#

May 15 2013 12:45 PM
I've been trying to delete a data in C# but it seems to be null, so here you are, please I need a support of any of you... thanks my friends

/*
 * Created by SharpDevelop.
 * User: fabreu
 * Date: 5/13/2013
 * Time: 1:40 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.CodeDom;

namespace ConsoleAgenda
{
 class Program
 {
 
 struct AgendaElectronica{
 
 public string Nombre;
 public string Email;
 public string Numero;
 public DateTime Fecha;
 
 
 }
 public static void Main(string[] args)
 {
 string Opcion;
 int CapacidadContactos = 5;
 int Cantidad = 0;
 AgendaElectronica[] Contactos = new Program.AgendaElectronica[CapacidadContactos];
 string salir;
 do{
 Console.WriteLine("Basic Diary:");
 
 Console.WriteLine("\n1-Add Contact:");
 Console.WriteLine("2-Search contact:");
 Console.WriteLine("3-Search every contact Added:");
 Console.WriteLine("4-Delete Data:");
 Console.WriteLine("0-Log out:");
 Opcion = Console.ReadLine();
 
 switch (Opcion) {
 case "1":
 if (Cantidad < CapacidadContactos) {
 Console.WriteLine("Contact range: {0}",Cantidad + 1);
 Console.WriteLine("\nType the contact you wish:");
 Contactos[Cantidad].Nombre = Console.ReadLine();
 
 Console.WriteLine("Contact's BirthDay:");
 Contactos[Cantidad].Fecha = Convert.ToDateTime(Console.ReadLine());
 Console.WriteLine("Contact's E-Mail:");
 Contactos[Cantidad].Email = Console.ReadLine();
 
 Console.WriteLine("Contact's Name:");
 Contactos[Cantidad].Numero = Console.ReadLine();
 
 Cantidad++;
 Console.WriteLine();
 
 } 
 
 else Console.WriteLine("Data base full!:");
 break;
 case "2": Console.WriteLine("type contact you need:");
 
 string buscar = Console.ReadLine();
 bool encontrado = false;
 for (int i = 0; i < Cantidad; i++) {
 if (buscar.ToUpper() == Contactos[i].Nombre.ToUpper()) {
 encontrado = true;
 Console.WriteLine("{0}: Name: {1} Number: {2} E-Mail: {3} BirthDay: {4}",i + 1
 Contactos[i].Nombre,Contactos[i].Numero,Contactos[i].Email,Contactos[i].Fecha);
 }
 if(!encontrado)
 Console.WriteLine("This Contact does not exist...{0}",!encontrado);
 
 }
 break;
 
 default: Console.WriteLine("Wrong!!!");
 Console.Clear();
 Console.ForegroundColor = ConsoleColor.DarkYellow; 
 Console.WriteLine();
 break;
 case "3"/*Me dá una lista de todas 
 las personas que tengo agregadas.*/
 if (Cantidad == 0) {
 Console.WriteLine("Data Base Empty!!!");
 }
 else
 
 for (int i = 0; i < Cantidad; i++) {
 Console.WriteLine("Data Found:{0}",Contactos[i].Nombre);
 
 
 }
 
 
 break;
 case"4":
 if (Cantidad == 0) {
 Console.WriteLine("Data Base Empty!!!");
 }
 else
 Console.WriteLine("type the contact you wish to delete...");
 for (int i = 0; i < Cantidad; i++) {
 Console.WriteLine("Data Found:{0}",Contactos[i].Nombre);
 
 Console.WriteLine("Do you want to delete this data:");
 Console.WriteLine("\nSelect one:");
 string Delete = Console.ReadLine();
 string Replace = string.Empty;
 if (Delete == Contactos[i].Nombre) {
 Console.WriteLine("Done:{0}",Replace.Replace(Contactos[i].Nombre,string.Empty)); //It suppose to be deleted but not work at all.
 }
 
 
 }
 break;
 }
 Console.WriteLine("Logging out:");
 salir = Console.ReadLine();
 }
 while(salir!= "0");
 
 
 Console.ReadKey(true);
 }
 }
}

Answers (3)