码迷,mamicode.com
首页 > Windows程序 > 详细

C# list 去重

时间:2016-06-23 11:03:17      阅读:616      评论:0      收藏:0      [点我收藏+]

标签:

 /// <summary>
        /// 汽车商标 获取
        /// Redis Key=zgqp315_Redis_TrademarkC_List
        /// </summary>
        /// <returns></returns>
        public static RedisJsonResult Get_TrademarkC()
        {
            //var redisClient = RedisManager.GetClient();
            var redisClient = new RedisClient("127.0.0.1", 6379);//redis服务IP和端口 

            int jsCode = 1;
            string jsMessage = "一切正常";
            List<TrademarkC> IList_TrademarkC = null;
            try
            {
                IList_TrademarkC = redisClient.Get<List<TrademarkC>>("zgqp315_Redis_TrademarkC_List");

                //根据 字段 FirstLetter 进行去重复 开始 
                var list_TrademarkC = IList_TrademarkC.GroupBy(m => m.FirstLetter.ToLower().Trim()).Select(m => new
                {
                    TrademarkId = m.FirstOrDefault().TrademarkId
                });
                IList_TrademarkC = IList_TrademarkC.Where(m => list_TrademarkC.Select(mo => mo.TrademarkId).Contains(m.TrademarkId)).ToList();
                //根据 字段 FirstLetter 进行去重复 结束 
            }
            catch (Exception ex)
            {
                jsCode = 0;
                jsMessage = ex.Message;
            }     

            return new RedisJsonResult()
            {
                JsCode = jsCode,
                JsMessage = jsMessage,
                data_TrademarkC = IList_TrademarkC,
                success = true,
            };
        }

 

C# list 去重

标签:

原文地址:http://www.cnblogs.com/foreverfendou/p/5609889.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!