I have a class:
public class MyObject
{
public string Code;
public string FullName;
}
I have a List of Myobject objects:
Code FullName
"ABC" "The abc company"
"BBC" "The bbc company"
"CPA" "The cpa company"
My requirement: a matched condition is a Code or FullName contains input word. With matched records, I will sort on Code before and FullName later.
Example:
When user input a string: “bc”, return a list:
Code FullName
"ABC" "The abc company"
"BBC" "The bbc company"
When user input a string: “pa”, return this list (note that "PA" is part of the Code, so it is displayed first):
Code FullName
"CPA" "The cpa company"
"ABC" "The abc company"
"BBC" "The bbc company"
Explain: When sorting, the Code field is more Priority than FullName field. Because, all of records contains the string “pa” but only the record with Code “CPA” contain “pa”, so it must be above.
PS: I’m using .NET 2.0/C# 2.0. String compare in filtering is not case-sensitive.
I’d do the following: