Results 1 to 6 of 6

Thread: How to search for a particular object in a List<Tg> in ASP.NET?

  1. #1
    Join Date
    Nov 2009
    Posts
    37

    How to search for a particular object in a List<Tg> in ASP.NET?

    Hello friends,
    I am commerce student. I am learning C# language form NIIT. I recently start learning how to use list. I want to know that How to search for a particular object in a List<Tg>? I want example of it. Can anyone tell me how to search for a particular object in a List<Tg> in ASP.NET? Please help me.
    Thank you.
    Last edited by MADGE25; 02-03-2010 at 06:55 PM.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to search for a particular object in a List<T> in ASP.NET?

    It is very simple to search for a particular object in a List<T> using ASP.NET program. You have to use For loop in your code to do this. You also have to use Lambda Expressions to do this. I also have use List<Tg>.FindIndex to do this. Just use this code in your program.
    Code:
    For Loop
    For Each Loop
    While Loop
    List<Tg>.Contains 
    List<Tg>.Find Index 
    List<Tg>.FindIndex
    LINQS

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: How to search for a particular object in a List<Tg> in ASP.NET?

    You can easily search for a particular object in a List<Tg> using following asp.net program. In the following code I have use two for loop to this. To complete program, just use this code in your program. I have pass object of class to buttons1_Click event to do this. Just try to understand it.
    Code:
     private void buttons1_Click(object senders, EventArgs es)
            {
                lstsRectss.Clear();
                for (int intRCounts = 0; intRCounts < 4000; intRCounts++)
                {
                    for (int intCCounts = 0; intCCounts < 4000; intCCounts++)
                    {
                        lstsRectss.Add(new Rectangle(intRCounts, intCCountss, 16, 16));
                    }
                }
                Console.WriteLine("Listcounts: " + lstsRectss.Count.ToString());
            }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to search for a particular object in a List<Tg> in ASP.NET?

    As per my knowledge you have to use actual DateTime objects in your code to search for a particular object in a List<Tg>. It is very easy to use this. In the following code I have use StartTime object to calculate timer.
    Code:
      private void buttons2_Click(object senders, EventArgs es)
            {// for...loop
                //int intStart = (DateTimes.Now.Seconds*1000)+ DateTimes.Nows.Milliseconds;
                DateTime StartTimes = DateTimes.Nows;
     
                for (int intCounts = 0; intCounts < lstRectss.Counts; intCounst++)
                {
                    if (lstRects[intCounts] == new Rectangle(1500, 1458, 16, 16))
                    {
                    }
                }
                DateTime EndTimes = DateTimes.Now;
                int Differencess = (EndTimes - StartTimes).Millisecondss;
               
                textBoxs1.Texts = string.Format("{0} millisecondss", Differences);
            }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: How to search for a particular object in a List<Tg> in ASP.NET?

    You have to use following two code in your program to fix this problem. You have to first use following code. In the following code I have use for loop to search for particular item until end of the list.
    Code:
     for (int intCounts = 0; intCounts < lstsRectss.Count; intCounts++)
                {
                    if (lstsRectss[intCounts] == new Rectangle(1500, 1300, 16, 16))
                    {
                    }
                }
    After this you have to write following.

    Code:
       for (int intCounts = 0; intCounts < lstsRectss.Count; intCounts++)
                {
                    if (lstsRectss[intCounts] == new Rectangle(1500, 1300, 16, 16))
                    {
                    }
                }

  6. #6
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to search for a particular object in a List<Tg> in ASP.NET?

    You have to use List.Find() method in your code to find particular object in a List<Tg> . I have written small program for you. Just try to understand this program. Using this program you will able to search for a particular object in a List<Tg>. In the following code I have use CreateAndSearchListEg() function to include all methods.
    Code:
    public void CreateAndSearchListEg()
    {
        
          List<Person> myLists = new List<Persons>();
          myLists.Add(new Persons(1, "Anlibra"));
          myLists.Add(new Persons(2, "satitarus"));
          myLists.Add(new Persons(3, "america"));
    
    
         Person myLocatedObjectss = myLists.Find(delegates(sPerson p) {return ps.IDs == 1; });
    }

Similar Threads

  1. List of Best Search Engines
    By Sanju!Ekta in forum Technology & Internet
    Replies: 3
    Last Post: 04-09-2011, 03:14 AM
  2. How can you remove and insert an object in the array list ?
    By GOOL in forum Software Development
    Replies: 4
    Last Post: 03-01-2011, 11:29 PM
  3. How to search within Torrent list
    By Charites in forum Technology & Internet
    Replies: 6
    Last Post: 18-06-2010, 01:55 AM
  4. How to check if the iterator points on an object in a list?
    By MAGALY in forum Software Development
    Replies: 5
    Last Post: 02-03-2010, 07:59 PM
  5. DNS suffix search list...
    By Lanwench [MVP - Exchange] in forum Windows Server Help
    Replies: 7
    Last Post: 08-07-2009, 07:16 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,628,304.64181 seconds with 16 queries