Show / Hide Table of Contents

Class ArrayInfo

This class organizes constants and routines for working with arrays. The constants are mostly synonyms for constants that exist in other classes and assemblies.

Since static classes are implicitly sealed, this class cannot be inherited.

Inheritance
System.Object
ArrayInfo
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: WizardWrx
Assembly: WizardWrx.Common.dll
Syntax
public static class ArrayInfo
Remarks

For ease of access, I promoted the classes that expose only constants to the root of the WizardWrx namespace.

Fields

| Improve this Doc View Source

ARRAY_FIRST_ELEMENT

Since array subscripts start at zero, the first element of any array is zero. Since the same holds for most things that go into square brackets or are called some kind of index, this constant works as well with indexes.

Declaration
public const int ARRAY_FIRST_ELEMENT = 0
Field Value
Type Description
System.Int32
See Also
ARRAY_IS_EMPTY
ARRAY_INVALID_INDEX
ARRAY_SECOND_ELEMENT
INDEX_FROM_ORDINAL
NEXT_INDEX
ORDINAL_FROM_INDEX
| Improve this Doc View Source

ARRAY_INVALID_INDEX

It follows from the fact that array indices count from zero that anything less is invalid.

Declaration
public const int ARRAY_INVALID_INDEX = -1
Field Value
Type Description
System.Int32
See Also
ARRAY_FIRST_ELEMENT
ARRAY_IS_EMPTY
ARRAY_SECOND_ELEMENT
INDEX_FROM_ORDINAL
NEXT_INDEX
ORDINAL_FROM_INDEX
| Improve this Doc View Source

ARRAY_IS_EMPTY

The Length and LongLength properties of an array return zero (ARRAY_IS_EMPTY) when the array is empty.

Declaration
public const int ARRAY_IS_EMPTY = 0
Field Value
Type Description
System.Int32
See Also
ARRAY_FIRST_ELEMENT
ARRAY_INVALID_INDEX
ARRAY_SECOND_ELEMENT
INDEX_FROM_ORDINAL
NEXT_INDEX
ORDINAL_FROM_INDEX
| Improve this Doc View Source

ARRAY_NEXT_INDEX

The next index is plus one, which is ambiguous, at best, in code.

Declaration
public const int ARRAY_NEXT_INDEX = 1
Field Value
Type Description
System.Int32
See Also
NEXT_INDEX
| Improve this Doc View Source

ARRAY_SECOND_ELEMENT

There is an amazing number of situations that require a refeerence to the second element of an array or list.

Declaration
public const int ARRAY_SECOND_ELEMENT = 1
Field Value
Type Description
System.Int32
See Also
ARRAY_FIRST_ELEMENT
ARRAY_IS_EMPTY
ARRAY_INVALID_INDEX
INDEX_FROM_ORDINAL
NEXT_INDEX
ORDINAL_FROM_INDEX
| Improve this Doc View Source

INDEX_FROM_ORDINAL

If ORDINAL_FROM_INDEX is +1, then its inverse should be -1. Thus, both operations are additions, which are typically a tad faster, since they don't have to manage a Carry flag.

Declaration
public const int INDEX_FROM_ORDINAL = -1
Field Value
Type Description
System.Int32
See Also
ORDINAL_FROM_INDEX
ARRAY_FIRST_ELEMENT
ARRAY_IS_EMPTY
ARRAY_INVALID_INDEX
ARRAY_SECOND_ELEMENT
NEXT_INDEX
ORDINAL_FROM_INDEX
| Improve this Doc View Source

MSO_COLLECTION_FIRST_ITEM

Indexing of collections of Microsoft Office objects begins at plus one.

Declaration
public const int MSO_COLLECTION_FIRST_ITEM = 1
Field Value
Type Description
System.Int32
See Also
ARRAY_FIRST_ELEMENT
| Improve this Doc View Source

NEXT_INDEX

The next index is plus one, which is ambiguous, at best, in code. listings.

Declaration
public const int NEXT_INDEX = 1
Field Value
Type Description
System.Int32
See Also
ARRAY_FIRST_ELEMENT
ARRAY_IS_EMPTY
ARRAY_INVALID_INDEX
ARRAY_SECOND_ELEMENT
INDEX_FROM_ORDINAL
ORDINAL_FROM_INDEX
ARRAY_NEXT_INDEX
MSO_COLLECTION_FIRST_ITEM
| Improve this Doc View Source

ORDINAL_FROM_INDEX

This grain of syntactic sugar is used in OrdinalFromIndex and made visible as documentation and for coding similar math inline when space permits.

Declaration
public const int ORDINAL_FROM_INDEX = 1
Field Value
Type Description
System.Int32
See Also
ARRAY_FIRST_ELEMENT
ARRAY_IS_EMPTY
ARRAY_INVALID_INDEX
ARRAY_SECOND_ELEMENT
INDEX_FROM_ORDINAL
NEXT_INDEX
INDEX_FROM_ORDINAL

Methods

| Improve this Doc View Source

IndexFromOrdinal(Int32)

Given an ordinal, such as an array element count, return the equivalent index (subscript) value.

Declaration
public static int IndexFromOrdinal(int pintOrdinal)
Parameters
Type Name Description
System.Int32 pintOrdinal

Specify the ordinal to convert.

Returns
Type Description
System.Int32

The return value is the index equivalent to pintIndex.

Remarks

Mathematically, the index is pintOrdinal - ORDINAL_FROM_INDEX. Hence, this routine is syntactic sugar, which a good optimizer will optimize away by generating the code inline.

See Also
OrdinalFromIndex(Int32)
| Improve this Doc View Source

OrdinalFromIndex(Int32)

Given an index, such as an array subscript, return the equivalent ordinal value.

Declaration
public static int OrdinalFromIndex(int pintIndex)
Parameters
Type Name Description
System.Int32 pintIndex

Specify the index to convert.

Returns
Type Description
System.Int32

The return value is the ordinal equivalent to pintIndex.

Remarks

Mathematically, the ordinal is pintIndex + ORDINAL_FROM_INDEX. Hence, this routine is syntactic sugar, which a good optimizer will optimize away by generating the code inline.

See Also
IndexFromOrdinal(Int32)
| Improve this Doc View Source

RemoveAt<T>(T[], Int32)

This method removes the element at index (subscript) pintIndex from array parr.

Declaration
public static T[] RemoveAt<T>(this T[] parr, int pintIndex)
Parameters
Type Name Description
T[] parr

Specify the array from which the element at subscript pintIndex should be removed.

System.Int32 pintIndex

Specify the zero-based index (subscript) of the element to be removed from array parr.

Returns
Type Description
T[]

The return value is a new array of type T from which the element at subscript pintIndex has been removed.

Type Parameters
Name Description
T

The type parameter is unconstrained, since the relevant concern is that the input is an array.

Remarks

This method is implemented as an extension method.

As mentioned by the article cited herein, since arrays are immutable objects, the only way to plysically remove an element from it is by creating a new array and copying into it every element except the one to be excluded.

Examples

Assume an array that contains at least 5 elements, so that 4 is a valid index (subscript).

astrArrayOfStrings = astrArrayOfStrings.RemoveAt ( 4 );

As is true of string objects, which are also immutable, you must return into a new variable by using an assignment statement. Note, however, that you may reuse the variable name just as you might with an extension method on System.String.

See Also

ListInfo
MagicNumbers
PathPositions
SpecialCharacters
  • Improve this Doc
  • View Source
Back to top Generated by DocFX