C#自定义对象列表 - 使用SQL Like语句查找对象

时间:2014-12-24 11:29:03

标签: c# list datatable

我曾经有一个数据表,我会使用以下方法查询:

 rows = dtpc.Select("POSTCODE LIKE '" + postcodeID + "%'");

这将返回许多行,然后我可以从数据表中删除它。

现在我使用的是一个自定义项列表而不是数据表。

 [Serializable]
    public class CUSTOMEROBJECT
    {
        public string Rep_code { get; set; }

        public string Int_rep_hou { get; set; }

        public string Int_rep_key { get; set; }

        public string Fullname { get; set; }

        public string Custcode { get; set; }

        public string Category { get; set; }

        public string Address1 { get; set; }

        public string Address2 { get; set; }

        public string Address3 { get; set; }

        public string Postcode { get; set; }

        public string Country { get; set; }

        public string Telephone { get; set; }

        public double Lat { get; set; }

        public double Lng { get; set; }

        public string County { get; set; }
    }

如何使用与上面使用的LIKE语句类似的方法找到一系列客户对象?

1 个答案:

答案 0 :(得分:2)

您可以使用LINQ

customerList.Where(c => c.Postcode.StartsWith(postcodeID.ToString()));