San24
asked on
LINQ Vs Hard Coding
Experts,
I`m using LINQ to retrieve some objects based on some property. Everything works great. I was wondering if there was a different way of doing it. Lets say in C# code.
What would be my algorithm be? Do I have to go through each element individually, check the property? Basically I want to look for a property and then order them according to a different property.
In the example, I get a sublist based on Tag, order it by Time.
Here is what I`m doing in LINQ. Code examples would be really helpful.
I`m using LINQ to retrieve some objects based on some property. Everything works great. I was wondering if there was a different way of doing it. Lets say in C# code.
What would be my algorithm be? Do I have to go through each element individually, check the property? Basically I want to look for a property and then order them according to a different property.
In the example, I get a sublist based on Tag, order it by Time.
Here is what I`m doing in LINQ. Code examples would be really helpful.
SubList = (from Obj in MainList
orderby Obj.Time
where Obj.IDTag == Tag
select Obj).ToList();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Kaufmed :
Can I use the sort this way?
Then I could just do a results.Sort();
For some reason this doesn`t seem to work.
Can I use the sort this way?
Then I could just do a results.Sort();
For some reason this doesn`t seem to work.
#region IComparable<SomeObj> Members
int IComparable<Trajectory>.CompareTo(SomeObj Other)
{
return Other.Time.CompareTo(Time);
}
#endregion
ASKER
Let me keep you posted.