reflection on List and printing values

前端 未结 6 907
眼角桃花
眼角桃花 2020-12-20 18:31

I wrote a method that accepts a generic parameter and then it prints its properties. I use it to test my web service. It\'s working but I want to add some features that I do

6条回答
  •  臣服心动
    2020-12-20 19:29

    I usually prints list with a , between each item.

    To make that easy I have created a simple extension method:

    public static class ListEx
    {
        public static string StringJoin(this IEnumerable items)
        {
            return string.Join(", ", items);
        }
    }
    

    Call the method as myList.StringJoin().

    You can of course modify the method to use another delimiter och call string.Join directly.

提交回复
热议问题