Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string str = "1,2,3;2,3,4;4,5,6";
- var arr = str
- .Split(';')
- .Select(x => x.Split(','))
- .Select(x => new
- {
- first = x[0],
- second = x[1],
- third = x[2]
- })
- .ToList();
- Enumerable.WhereSelectArrayIterator<string, <>f__AnonymousType0#10<string, string, string>> { { first = "1", second = "2", third = "3" }, { first = "2", second = "3", third = "4" }, { first = "4", second = "5", third = "6" } }
- List<string>(3) { "1t2t3", "2t3t4", "4t5t6" }
- arr.Select(x => x.first + "t" + x.second + "t" + x.third).ToList();
- arr.Select(x => x.first, x.second, x.third).ToList();
- public static IEnumerable<string> JoinByTab<T>(this IEnumerable<T> list) where T : class
- {
- PropertyInfo[] properties = list.FirstOrDefault().GetType().
- GetProperties(BindingFlags.Public | BindingFlags.Instance);
- var listStr = list
- .Select(x => String.Join("t", properties.Select(y => y.GetValue(x, null).ToString())));
- return listStr;
- }
- public static IEnumerable<string> Join<T>(this IEnumerable<T> list,
- string separator,
- params Func<T, string>[] properties) where T : class
- {
- foreach (var element in list)
- {
- yield return string.Join(separator, properties.Select(p => p(element)));
- }
- }
- var result = arr.Join("t",
- x => x.first,
- x => x.second,
- x => x.third)
- .ToList();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement