本文整理汇总了C#中System.Array.GetLongLength方法的典型用法代码示例。如果您正苦于以下问题:C# Array.GetLongLength方法的具体用法?C# Array.GetLongLength怎么用?C# Array.GetLongLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Array
的用法示例。
在下文中一共展示了Array.GetLongLength方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatArrayTypeName
private string FormatArrayTypeName(Type arrayType, Array arrayOpt, ObjectFormattingOptions options)
{
StringBuilder sb = new StringBuilder();
// print the inner-most element type first:
Type elementType = arrayType.GetElementType();
while (elementType.IsArray)
{
elementType = elementType.GetElementType();
}
sb.Append(FormatTypeName(elementType, options));
// print all components of a jagged array:
Type type = arrayType;
do
{
if (arrayOpt != null)
{
sb.Append('[');
int rank = type.GetArrayRank();
bool anyNonzeroLowerBound = false;
for (int i = 0; i < rank; i++)
{
if (arrayOpt.GetLowerBound(i) > 0)
{
anyNonzeroLowerBound = true;
break;
}
}
for (int i = 0; i < rank; i++)
{
int lowerBound = arrayOpt.GetLowerBound(i);
long length = arrayOpt.GetLongLength(i);
if (i > 0)
{
sb.Append(", ");
}
if (anyNonzeroLowerBound)
{
AppendArrayBound(sb, lowerBound, options.UseHexadecimalNumbers);
sb.Append("..");
AppendArrayBound(sb, length + lowerBound, options.UseHexadecimalNumbers);
}
else
{
AppendArrayBound(sb, length, options.UseHexadecimalNumbers);
}
}
sb.Append(']');
arrayOpt = null;
}
else
{
AppendArrayRank(sb, type);
}
type = type.GetElementType();
}
while (type.IsArray);
return sb.ToString();
}
示例2: CollectMultiArrayItems
private void CollectMultiArrayItems(List<STypeInstanceProxy> items, Array array, int dimension, params long[] indices)
{
// visszaállítási adatok mentése
long originalIndicesValueOnDimension = 0;
if (dimension + 1 < array.GetType().GetArrayRank())
{
originalIndicesValueOnDimension = indices[dimension + 1];
}
for (long i = 0; i < array.GetLongLength(dimension); i++)
{
STypeInstanceProxy proxy = null;
indices[dimension] = i;
if (indices.Length - 1 == dimension)
{
object value = array.GetValue(indices);
if (value != null)
{
proxy = GetTypeInstanceProxy(value, value.GetType()); // array.GetType().GetElementType()
}
}
else
{
proxy = (STypeInstanceProxy)GetTypeInfo(array.GetType().GetElementType()).Clone();
bool firstTime = false;
proxy.InstanceId = mGenerator.GetId(proxy, out firstTime); //mProxyIdGenerator;
proxy.InstanceValue = dimension; // level of the array
proxy.IsArrayDimensionRepresentation = true;
mReferenceVsTypeInstances.Add(proxy.InstanceId, proxy);
}
items.Add(proxy);
if (dimension + 1 < array.GetType().GetArrayRank())
{
proxy.ArrayItems = new List<STypeInstanceProxy>();
CollectMultiArrayItems(proxy.ArrayItems, array, dimension + 1, indices);
indices[dimension + 1] = originalIndicesValueOnDimension;
}
}
}
示例3: DeclareArrayInitializer
private void DeclareArrayInitializer(Array array, int dim, long[] indices, StringBuilder sb)
{
long length = array.GetLongLength(dim);
sb.Append("(");
if (length == 1)
{
sb.Append("0 => ");
}
int linelen = 0;
for (long i = 0; i < length; i++)
{
if (i > 0)
sb.Append(",");
++linelen;
if (linelen < 200)
{
sb.Append(" ");
}
else
{
sb.AppendLine();
linelen = 0;
}
indices[dim] = i;
if (dim < array.Rank - 1)
{
DeclareArrayInitializer(array, dim + 1, indices, sb);
}
else
{
object element = array.GetValue(indices);
string value = GetValueID(element);
sb.Append(value);
linelen += value.Length;
}
}
sb.Append(")");
}
示例4: CollectArrayItems
private void CollectArrayItems(List<STypeInstanceProxy> items, Array array, params long[] indices)
{
long length = array.GetLongLength(0);
for (long i = 0; i < length; i++)
{
indices[0] = i;
object arrayItem = array.GetValue(indices);
if (arrayItem == null)
{
items.Add(null);
}
else if (arrayItem.GetType().IsGenericType && arrayItem.GetType().GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
{
items.Add(GetTypeInstanceProxy(arrayItem, arrayItem.GetType()));
}
else
{
items.Add(GetTypeInstanceProxy(arrayItem, null));
}
}
}
示例5: DeclareArrayInitializer
private void DeclareArrayInitializer(Array array, int dim, long[] indices, StringBuilder sb, string name)
{
long length = array.GetLongLength(dim);
//sb.Append(" /*");
//if (length == 1)
//{
// sb.Append("0 => ");
//}
int linelen = 0;
for (long i = 0; i < length; i++)
{
if (i > 0)
sb.Append(";");
++linelen;
if (linelen < 200)
{
sb.Append(" ");
}
else
{
sb.AppendLine();
linelen = 0;
}
indices[dim] = i;
if (dim < array.Rank - 1)
{
DeclareArrayInitializer(array, dim + 1, indices, sb, name);
}
else
{
object element = array.GetValue(indices);
string value = GetValueID(element);
if(dim == 0)
sb.Append(name + "[" + i + "] = " + value);
else
sb.Append(name + "[" + dim + "][" + i + "] = " + value);
linelen += value.Length;
}
}
sb.Append(";");
sb.AppendLine();
}