Click here to Skip to main content
15,991,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi every one! Can we eatablish any relation between two lists?I just want to query the list and find the related result from other list.Please suggest some idea

class GeneralClass
    {
        //public List<int> Student_RollNumber = new List<int>();
        //public List<string> Student_Name = new List<string>();
        private List<int> _student_rollnumber = new List<int>();
        private List<string> _student_name = new List<string>();
        public List<int> Student_RollNumber
        {
            get { return _student_rollnumber; }
            set { _student_rollnumber = value; }
        }
        public List<string> Student_Name
        {
            get { return _student_name; }
            set { _student_name = value; }
        }
    }


private void btn_save_Click(object sender, EventArgs e)
        {
            try
            {
                obj.Student_RollNumber.Add(int.Parse(txtbx_rollnum.Text));
                obj.Student_Name.Add(txtbx_SName.Text);
                MessageBox.Show("Data saved");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Message from form");
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
               var result = obj.Student_Name.Contains(txtbx_find.Text).ToString();
              MessageBox.Show(result.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }





Here i want the Student name when i search for Rollnumber.Can we have multiple column's in a List.
Posted
Updated 14-Sep-10 0:31am
v2

You could use a Dictionary for that.

http://dotnetperls.com/dictionary[^]
MSDN Dictionary[^]

some wiki info on associative arrays:
http://en.wikipedia.org/wiki/Associative_array[^]

Good luck!

UPDATE SM:
Fixed first link and added one more link to the answer.
 
Share this answer
 
v2
Comments
hemantwithu 14-Sep-10 7:13am    
Those two links are not working
Sandeep Mewara 14-Sep-10 12:36pm    
First one is not working, though second one is!
Sandeep Mewara 14-Sep-10 12:39pm    
To Laxmi: Corrected the link and added one more for you.
To N.J.: Hope you won't mind :)
What about simply storing a class instance in the list, instead of just ints/strings:

public class MyListItem
{
    public int StudentRoleNumber { get; set; }
    public string StudentName { get; set; }
}

private readonly List<mylistitem> _students = new List<mylistitem>();</mylistitem></mylistitem>


Something like that...

Cheers
Uwe
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900