Mercurial > hg > ucis.core
comparison Util/ArrayUtil.cs @ 88:c9da306e06c9
FBGUI: Improved FBGContainerControl thread safety
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Tue, 11 Mar 2014 17:45:48 +0100 |
parents | 3352f89cf6f5 |
children | ebdff34b9e4f |
comparison
equal
deleted
inserted
replaced
83:4ca44dd25a6a | 88:c9da306e06c9 |
---|---|
160 public static int AddUnique<T>(ref T[] array, T item) { | 160 public static int AddUnique<T>(ref T[] array, T item) { |
161 int index = Array.IndexOf(array, item); | 161 int index = Array.IndexOf(array, item); |
162 if (index == -1) index = Add(ref array, item); | 162 if (index == -1) index = Add(ref array, item); |
163 return index; | 163 return index; |
164 } | 164 } |
165 public static Boolean Remove<T>(ref T[] array, T item) { | |
166 if (array == null) return false; | |
167 int index = Array.IndexOf(array, item); | |
168 if (index == -1) return false; | |
169 T[] newarray = new T[array.Length - 1]; | |
170 if (index > 0) Array.Copy(array, 0, newarray, 0, index); | |
171 if (index < array.Length - 1) Array.Copy(array, index + 1, newarray, index, array.Length - index - 1); | |
172 array = newarray; | |
173 return true; | |
174 } | |
165 } | 175 } |
166 } | 176 } |