zoukankan      html  css  js  c++  java
  • ListHelper

     

        public static class ListHelper
        {
            /// <summary>
            /// 将list集合 中的某一属性 组装成“,”分割的字符串(方法一)
            /// </summary>
            /// <typeparam name="T"></typeparam>
            /// <param name="list"></param>
            /// <param name="str"></param>
            /// <returns></returns>
            public static string GetStr<T>(List<T> list, string str)
            {
                string result = "";
                foreach (var item in list)
                {
                    string value = item.GetType().GetProperty(str).GetValue(item, null) + "";
                    if (!string.IsNullOrEmpty(value))
                    {
                        result = result + value + ",";
                    }
                }
                return result.TrimEnd(',');
            }
            /// <summary>
            /// 将list集合 中的某一属性 组装成“,”分割的字符串(方法二)
            /// </summary>
            /// <param name="Listobj"></param>
            /// <param name="str"></param>
            /// <returns></returns>
            public static string GetStr(dynamic Listobj, string str)
            {
                string result = "";
                foreach (dynamic itemClass in Listobj)
                {
                    string value = itemClass.GetType().GetProperty(str).GetValue(itemClass, null) + "";
                    if (!string.IsNullOrEmpty(value))
                    {
                        //itemClass.str
                        result = result + value + ",";
                    }
                }
                return result.TrimEnd(',');
            }
        }
  • 相关阅读:

    python内存管理
    python-继承类执行的流程
    Redis-key的设计技巧
    Redis-误操作尝试恢复
    Python3之hashlib
    面相对象
    设计模式
    RESTful API规范
    Django中间件执行流程
  • 原文地址:https://www.cnblogs.com/-hao/p/10475449.html
Copyright © 2011-2022 走看看