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.
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
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());
}
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);
}
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))
{
}
}
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; });
}