Ensures that the short array cannot hold more than maxCapacity elements. : Array Util « Collections Data Structure « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Collections Data Structure » Array UtilScreenshots 
Ensures that the short array cannot hold more than maxCapacity elements.
 

/*
 Copyright 1999 CERN - European Organization for Nuclear Research.
 Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose 
 is hereby granted without fee, provided that the above copyright notice appear in all copies and 
 that both that copyright notice and this permission notice appear in supporting documentation. 
 CERN makes no representations about the suitability of this software for any purpose. 
 It is provided "as is" without expressed or implied warranty.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace DiscoveryLogic.Common.Numeric
{
    public class Arrays : System.Object
    {

        /// <summary> Ensures that the specified array cannot hold more than <tt>maxCapacity</tt> elements.
        /// An application can use this operation to minimize array storage.
        /// <p>
        /// Returns the identical array if <tt>array.length &lt;= maxCapacity</tt>.
        /// Otherwise, returns a new array with a length of <tt>maxCapacity</tt>
        /// containing the first <tt>maxCapacity</tt> elements of <tt>array</tt>.
        /// 
        /// </summary>
        /// <param name="maxCapacity">  the desired maximum capacity.
        /// </param>
        public static short[] trimToCapacity(short[] array, int maxCapacity)
        {
            if (array.Length > maxCapacity)
            {
                short[] oldArray = array;
                array = new short[maxCapacity];
                Array.Copy(oldArray, 0, array, 0, maxCapacity);
            }
            return array;
        }
   }
}

   
  
Related examples in the same category
1.Return the average of the given values
2.Return the percentage of a given value.
3.return the min value in the list of double
4.return the max value in the list of double
5.Returns a string representation of the sbyte array
6.Returns a string representation of the char array
7.Returns a string representation of the double array
8.Returns a string representation of the float array
9.Returns a string representation of the int array
10.Returns a string representation of the long array
11.Returns a string representation of the object array
12.Returns a string representation of the short value array
13.Returns a string representation of the bool value array
14.Ensures that the sbyte array cannot hold more than maxCapacity elements.
15.Ensures that the char array cannot hold more than maxCapacity elements.
16.Ensures that the double array cannot hold more than maxCapacity elements.
17.Ensures that the float array cannot hold more than maxCapacity elements.
18.Ensures that the int array cannot hold more than maxCapacity elements.
19.Ensures that the long array cannot hold more than maxCapacity elements.
20.Ensures that the object array cannot hold more than maxCapacity elements.
21.Ensures that the bool array cannot hold more than maxCapacity elements.
22.Copy an array into another array.
23.Swap two elements in a array
24.Generic Growable Array
25.foreach is used to display the contents of an array of integers.
26.Are two arrays equal.
27.Are thos two arrays having the save contents
28.Convert object array to string
29.Get array size
30.Convert array content to generic type array
31.Searches for the specified object and returns the index of the first occurrence within the entire one-dimensional System.Array.
32.Creates a new array with just the specified elements.
33.Array 2D
34.Get a array of object from a enum datatype.
35.Reinitializes an int array to the given value in an optimized way: intArraySet
36.Returns a Boolean indicating whether the Array is Empty (is Null or has a length of zero).
37.Places elements from an enumerable into an array.
38.Bit Array 2D
39.Counting the distribution of the values in an array.
40.Collection of static methods for operations on arrays
41.Char Array Writer
42.Computes the indices
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.