PDA

View Full Version : سوال: مشکل ا انواع کلکسیون ها



AliRezaPro
چهارشنبه 27 شهریور 1387, 17:11 عصر
راستش یه برنامه خیلی ساده نوشتم که با مشکل رو برو شدم
اینم کدش

public struct Customers
{
public string FirstName;
public string LastName;
public string Email;
public override string ToString()
{
return FirstName +"(" +Email+")" + LastName;

}
public string Name
{
get
{
return FirstName + " " + LastName;
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Customer
{
public partial class Form1 : Form
{
private Hashtable ObjCustomer = new Hashtable();

public Customers SelectedCustomer
{
get
{
return (Customers)lstCustomer.Items[lstCustomer.SelectedIndex];
}
}

private ArrayList ObjCustomer = new ArrayList();


public void CreatCustomer(string FirstName,string LastName,string Email)
{
Customers ObjNewCustomer;
ObjNewCustomer.FirstName=FirstName;
ObjNewCustomer.LastName = LastName;
ObjNewCustomer.Email = Email;
ObjCustomer.Add(Email.ToLower(), ObjNewCustomer);
lstCustomer.Items.Add(ObjNewCustomer);
}

private void DisplayeCustomer(Customers ObjCustomer)
{
txtName.Text = ObjCustomer.Name;
txtFirstName.Text = ObjCustomer.FirstName;
txtLastName.Text = ObjCustomer.LastName;
txtEmail.Text = ObjCustomer.Email;
}

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Customers ObjCustomer;
ObjCustomer.FirstName = "MIchel";
ObjCustomer.LastName = "Basini";
ObjCustomer.Email = "Michel@Yahoo.com";
DisplayeCustomer(ObjCustomer);

CreatCustomer("ALiReza" , "Ghorbane" , "MAn7Tomai@Yahoo.com");
CreatCustomer("Mohammad" , "Ghorbai" ,"Mamali@yahoo.com");
CreatCustomer("Saman" , "AliAghaee" , "SAman@yahoo.com");

}

private void Form1_Load(object sender, EventArgs e)
{

}

private void lstCustomer_SelectedIndexChanged(object sender, EventArgs e)
{
DisplayeCustomer(SelectedCustomer);
}

private void button2_Click(object sender, EventArgs e)
{
if (lstCustomer.SelectedIndex== -1)
{
MessageBox.Show("You Must Select Customer To " + "Delete!","Structure Demo");
return;

}

DialogResult Result=MessageBox.Show("Are You Sure You Want To Delete" + "?","Struct Demo",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if (Result == DialogResult.Yes)
{
Customers ObjCustomerToDelete = SelectedCustomer;
ObjCustomer.Remove(txtEmail.Text.ToLower());
lstCustomer.Items.Remove(ObjCustomerToDelete);
}

}

private void button3_Click(object sender, EventArgs e)
{
if(ObjCustomer.Contains(txtEmail.Text.ToLower())== true)
{
MessageBox.Show("The Customer Name is : "+((Customers)ObjCustomer[txtEmail.Text.ToLower()]).Name,"Structure Demo");



{
MessageBox.Show("there is No Custome rwithe The " + "Email Address:"+txtEmail.Text,"Structure Demo");
}
}
}
}
}
اینم ارورش:

The type 'Customer.Form1' already contains a definition for 'ObjCustomer

رضا عربلو
چهارشنبه 27 شهریور 1387, 21:18 عصر
ObjCustomer را یکبار به عنوان HashTable ویکبار بعنوان ArrayList تعریف کرده اید!!!!!!!!!!!!

AliRezaPro
چهارشنبه 27 شهریور 1387, 22:55 عصر
خوب باید 2تا متغیر تعریف کنم؟را حلش چیه؟

sinpin
شنبه 30 شهریور 1387, 08:53 صبح
خوب باید 2تا متغیر تعریف کنم؟را حلش چیه؟

شما نيازي به سطر زير نداريد :

private Hashtable ObjCustomer = new Hashtable();