comparison Util/ArrayUtil.cs @ 56:7c15c12ef965

Added new ArrayUtil.ToArray functions
author Ivo Smits <Ivo@UCIS.nl>
date Wed, 09 Oct 2013 13:56:35 +0200
parents f553f6e0a396
children 4714531734b3
comparison
equal deleted inserted replaced
55:ec222fb577dd 56:7c15c12ef965
1 using System; 1 using System;
2 using System.Collections;
2 using System.Collections.Generic; 3 using System.Collections.Generic;
3 4
4 namespace UCIS.Util { 5 namespace UCIS.Util {
5 public class ArrayUtil { 6 public class ArrayUtil {
6 public static T[] Slice<T>(T[] input, int offset) { 7 public static T[] Slice<T>(T[] input, int offset) {
10 public static T[] Slice<T>(T[] input, int offset, int count) { 11 public static T[] Slice<T>(T[] input, int offset, int count) {
11 if (offset < 0) offset = input.Length + offset; 12 if (offset < 0) offset = input.Length + offset;
12 if (count < 0) count = input.Length + count - offset; 13 if (count < 0) count = input.Length + count - offset;
13 T[] output = new T[count]; 14 T[] output = new T[count];
14 Array.Copy(input, offset, output, 0, count); 15 Array.Copy(input, offset, output, 0, count);
16 return output;
17 }
18 public static Object[] ToArray(ICollection input) {
19 Object[] output = new Object[input.Count];
20 input.CopyTo(output, 0);
21 return output;
22 }
23 public static T[] ToArray<T>(ICollection input) {
24 T[] output = new T[input.Count];
25 input.CopyTo(output, 0);
15 return output; 26 return output;
16 } 27 }
17 public static T[] ToArray<T>(ICollection<T> input) { 28 public static T[] ToArray<T>(ICollection<T> input) {
18 T[] output = new T[input.Count]; 29 T[] output = new T[input.Count];
19 input.CopyTo(output, 0); 30 input.CopyTo(output, 0);