You can use the below code if you using LINQ to Objects
private void button1_Click(object sender, EventArgs e)
{
List<Customer> customers = new List<Customer>();
customers.Add(new Customer { CustomerID = "A12I", CustomerName = "Palash" });
customers.Add(new Customer { CustomerID = "B20G", CustomerName = "Ankesh" });
customers.Add(new Customer { CustomerID = "A100I", CustomerName = "Subhadip" });
customers.Add(new Customer { CustomerID = "C12G", CustomerName = "Namita" });
var result = (from c in customers
where c.CustomerID.StartsWith("A") && c.CustomerID.EndsWith("I")
select c).ToList();
foreach (Customer c in result)
{
MessageBox.Show(c.CustomerName);
}
}
}
public class Customer
{
public string CustomerID;
public string CustomerName;
}
for Search A%I . In case Of Search %I% you can use String Contains method to do that In Case of LINQ to SQL You can Use the Syntax like
var result = (from c in db.Customers
where System.Data.Linq.SqlClient.SqlMethods.Like(c.CustomerID, "A%I")
select c).ToList();