本文整理汇总了C#中System.Array.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# Array.GetLength方法的具体用法?C# Array.GetLength怎么用?C# Array.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Array
的用法示例。
在下文中一共展示了Array.GetLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CodeRepresentation
public static string CodeRepresentation(Array a)
{
StringBuilder ret = new StringBuilder();
ret.Append(a.GetType().FullName);
ret.Append("(");
switch (a.Rank) {
case 1: {
for (int i = 0; i < a.Length; i++) {
if (i > 0) ret.Append(", ");
ret.Append(Ops.StringRepr(a.GetValue(i + a.GetLowerBound(0))));
}
}
break;
case 2: {
int imax = a.GetLength(0);
int jmax = a.GetLength(1);
for (int i = 0; i < imax; i++) {
ret.Append("\n");
for (int j = 0; j < jmax; j++) {
if (j > 0) ret.Append(", ");
ret.Append(Ops.StringRepr(a.GetValue(i + a.GetLowerBound(0), j + a.GetLowerBound(1))));
}
}
}
break;
default:
ret.Append(" Multi-dimensional array ");
break;
}
ret.Append(")");
return ret.ToString();
}
示例2: LoadData
// Load data
public void LoadData( Array array )
{
//
this.array = array;
// set column and row headers
FixedRows = 1;
FixedColumns = 1;
// Redim the grid
Redim( array.GetLength( 0 ) + FixedRows, array.GetLength( 1 ) + FixedColumns );
// Col Header Cell Template
columnHeader = new CellColumnHeaderTemplate( );
columnHeader.BindToGrid( this );
// Row Header Cell Template
rowHeader = new CellRowHeaderTemplate( );
rowHeader.BindToGrid( this );
// Header Cell Template (0,0 cell)
cellHeader = new CellHeaderTemplate( );
cellHeader.BindToGrid( this );
// Data Cell Template
dataCell = new CellArrayTemplate( array ); ;
dataCell.BindToGrid( this );
RefreshCellsStyle( );
}
示例3: ConvertArrayToShape
public Shape ConvertArrayToShape(Array data)
{
width = data.GetLength(1);
height = data.GetLength(0);
shape = new Shape();
double[] prevRow = ReadRow(data, 0);
for (int y = 1; y < height; y++)
{
double[] nextRow = ReadRow(data, y);
Vertex[] verts = GetRowOfVertices(nextRow, prevRow, y - 1);
shape.Vertices.AddRange(verts);
prevRow = nextRow;
}
return shape;
}
示例4: ArrayInfo
static void ArrayInfo(String name, Array a)
{
Console.Write("{0} has length={1} rank={2} [", name, a.Length, a.Rank);
for (int i = 0, stop=a.Rank; i<stop; i++)
Console.Write(" {0}", a.GetLength(i));
Console.WriteLine(" ]");
}
示例5: CombinatorialBase
// This is the GENERIC Type constructor.
protected CombinatorialBase(Array arrayObjects, int nKlass)
{
// Check the validity of the arguments
DoArgumentCheck(arrayObjects.Length, nKlass);
m_nKlass = nKlass;
// Always takes the ZERO (FIRST) dimension of the array. There is no
// problem in manipulation multidimensional arrays.
m_nMaxIndex = arrayObjects.GetLength(0) - 1;
m_arrayIndeces = new int[m_nKlass];
m_arrayIndecesDummy = new int[m_nKlass];
m_arrayCurrentObj = new TouchPoint2[m_nKlass];
// m_arrayCurrentCombination = Array.CreateInstance(
// arrayObjects.GetValue(0).GetType(), m_nKlass);
// Make a shallow copy of the source array.
// m_arrayObj = Array.CreateInstance( arrayObjects.GetValue(0).GetType(), arrayObjects.Length);
//m_arrayObj = Array.CreateInstance(Type.GetType("System.Object"), arrayObjects.Length);
//Array.Copy(arrayObjects, m_arrayObj, arrayObjects.Length);
//TODO: review code
m_arrayObj = new TouchPoint2[arrayObjects.Length];
Array.Copy(arrayObjects, m_arrayObj, arrayObjects.Length);
}
示例6: BuildDigitsRepresentingAllIndices
private static Digit BuildDigitsRepresentingAllIndices(Array subjectAsArray)
{
return Enumerable
.Range(0, subjectAsArray.Rank)
.Reverse()
.Aggregate((Digit) null, (next, rank) => new Digit(subjectAsArray.GetLength(rank), next));
}
示例7: Com2DArray2Array
//-------------------------------------------------------------------//
/// <summary>
/// Converts COM like 2dim array where one dimension is of length 1 to regular array.
/// </summary>
/// <param name="a">COM array</param>
/// <returns>regular array</returns>
public static object[] Com2DArray2Array(Array a)
{
if (a == null)
return null;
object[] converted = null;
switch (a.Rank)
{
case 1:
converted = new object[a.GetLength(0)];
for (var i = a.GetLowerBound(0); i <= a.GetUpperBound(0); i++)
{
converted[i] = a.GetValue(i);
}
break;
case 2:
{
var d1 = a.GetLength(0);
var d2 = a.GetLength(1);
var len = (d1 > d2) ? d1 : d2;
converted = new object[len];
var dim = (d1 > d2) ? 0 : 1;
for (var i = a.GetLowerBound(dim); i <= a.GetUpperBound(dim); i++)
{
converted[i - a.GetLowerBound(dim)] = a.GetValue((d1 == 1 ? a.GetLowerBound(0) : i),
(d2 == 1 ? a.GetLowerBound(1) : i));
}
}
break;
}
return converted;
}
示例8: ArrayLength
static long ArrayLength(Array array, int i)
{
long n = 1;
for ( ; i < array.Rank; i++ )
n *= array.GetLength(i);
return n;
}
示例9: AssertArray
static void AssertArray(Array array, params object[] expectedValues)
{
Program.Assert(array.GetLength(0) == expectedValues.Length, "The arrays lengths are differents");
for (int i = 0; i < expectedValues.Length; i++)
{
Program.Assert(array.GetValue(i).Equals(expectedValues[i]), "Unexpected values");
}
}
示例10: LoadData
// Load data
public void LoadData( Array array )
{
//
this.array = array;
behavior = new CellBehavior( array );
// set column and row headers
FixedRows = 1;
FixedColumns = 1;
// Redim the grid
Redim( array.GetLength( 0 ) + FixedRows, array.GetLength( 1 ) + FixedColumns );
// Header
this[0, 0] = new Header( );
// Column headers
for ( int i = 1; i < this.ColumnsCount; i++ )
{
ColumnHeader header = new ColumnHeader( i.ToString( ) );
header.EnableSort = false;
this[0, i] = header;
}
// Row headers
for ( int i = 1; i < this.RowsCount; i++ )
{
this[i, 0] = new RowHeader( i.ToString( ) );
}
// Data cells
Type type = array.GetValue( 0, 0 ).GetType( );
for ( int i = 1, ia = 0; i < this.RowsCount; i++, ia++ )
{
for ( int j = 1, ja = 0; j < this.ColumnsCount; j++, ja++ )
{
Cell cell = new Cell( array.GetValue( ia, ja ), type );
cell.Behaviors.Add( behavior );
this[i, j] = cell;
}
}
Colorize( );
}
示例11: ArrayTraverse
public ArrayTraverse(Array array)
{
_maxLengths = new int[array.Rank];
for (int i = 0; i < array.Rank; ++i)
{
_maxLengths[i] = array.GetLength(i) - 1;
}
Position = new int[array.Rank];
}
示例12: ArrayTraverse
public ArrayTraverse(Array array)
{
this.Position = new int[array.Rank];
this.maxLengths = new int[array.Rank];
for (int i = 0; i < array.Rank; i++)
{
this.maxLengths[i] = array.GetLength(i) - 1;
}
}
示例13: ArrayToString
/// <summary>
/// The array to string.
/// </summary>
/// <param name="array">
/// The array.
/// </param>
/// <returns>
/// The <see cref="string"/>.
/// </returns>
public static string ArrayToString(Array array)
{
StringBuilder text = new StringBuilder();
for (int i = 0; i < array.GetLength(0); i++)
{
if (i != array.GetLength(0) - 1)
{
text.Append(array.GetValue(i) + ", ");
}
else
{
text.Append(array.GetValue(i));
}
}
return text.ToString();
}
示例14: serializeArray
private void serializeArray(Array array)
{
m_ArrayData = new object[array.Length];
m_ArrayDims = new int[array.Rank];
for(var i=0; i<array.Rank; i++)
m_ArrayDims[i] = array.GetLength(i);
var idx = 0;
SerializationUtils.WalkArrayWrite(array, elm => m_ArrayData[idx++] = elm );
}
示例15: WriteArray
private void WriteArray(BinaryWriter bw, Array a, int dimension, params int[] indices)
{
if (a.Rank == dimension)
WriteCore(bw, a.GetValue(indices));
else
{
for (int i = 0; i < a.GetLength(dimension); i++)
WriteArray(bw, a, dimension + 1, indices.Append(i));
}
}