예제 #1
0
        /// <summary>
        /// Convert a range of an array to a read only array by copying its contents.
        /// The provided array may safely change after this call.
        /// </summary>
        public static ReadOnlyArray <T> From(T[] array, int start, int count)
        {
            Contract.RequiresNotNull(array);
            Contract.Requires(start >= 0);
            Contract.Requires(count >= 0);
            Contract.Requires((uint)start + (uint)count <= (uint)array.Length);

            T[] trimmed;
            if (count == 0)
            {
                // normalize
                trimmed = CollectionUtilities.EmptyArray <T>();
            }
            else
            {
                trimmed = new T[count];
                Array.Copy(array, start, trimmed, 0, count);
            }

            return(new ReadOnlyArray <T>(trimmed));
        }
예제 #2
0
 /// <summary>
 /// Class constructor
 /// </summary>
 protected SemaphoreSet()
 {
     SyncLock          = new object();
     SemaphoreLimits   = new List <int>();
     m_semaphoreUsages = CollectionUtilities.EmptyArray <int>();
 }
예제 #3
0
 /// <summary>
 /// Shallow copy constructor
 /// </summary>
 /// <param name="copy">the set whose structures will be shared with this instance</param>
 protected SemaphoreSet(SemaphoreSet copy)
 {
     SyncLock          = copy.SyncLock;
     SemaphoreLimits   = copy.SemaphoreLimits;
     m_semaphoreUsages = CollectionUtilities.EmptyArray <int>();
 }