Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- public static class Test
- {
- static void Main()
- {
- List<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
- Console.WriteLine(numbers.ToString<int>());
- numbers.IncreaseWidth(5);
- Console.WriteLine(numbers.ToString<int>());
- }
- }
- public static class IListExtensions
- {
- public static void IncreaseWidth(
- this IList<int> list,
- int amount)
- {
- for (int i = 0; i < list.Count; i++)
- {
- list[i] += amount;
- }
- }
- }
- public static class IEnumerableExtensions
- {
- public static string ToString<T>(
- this IEnumerable<T> enumeration)
- {
- StringBuilder result = new StringBuilder();
- result.Append("[");
- foreach (var item in enumeration)
- {
- result.Append(item.ToString());
- result.Append(", ");
- }
- if (result.Length > 1)
- result.Remove(result.Length - 2, 2);
- result.Append("]");
- return result.ToString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment