本文整理汇总了C#中Object.GetArrayLength方法的典型用法代码示例。如果您正苦于以下问题:C# Object.GetArrayLength方法的具体用法?C# Object.GetArrayLength怎么用?C# Object.GetArrayLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Object
的用法示例。
在下文中一共展示了Object.GetArrayLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StelemRef
static public unsafe void StelemRef(Object array, int index, object obj)
{
// This is supported only on arrays
Debug.Assert(array.EEType->IsArray, "first argument must be an array");
if (index >= array.GetArrayLength())
{
IntPtr addr = array.EEType->GetAssociatedModuleAddress();
Exception e = EH.GetClasslibException(ExceptionIDs.IndexOutOfRange, addr);
throw e;
}
if (obj != null)
{
EEType* arrayElemType = array.EEType->RelatedParameterType;
if (!CastCache.AreTypesAssignableInternal(obj.EEType, arrayElemType, AssignmentVariation.BoxedSource))
{
// If object type implements ICastable then there's one more way to check whether it implements
// the interface.
if (!obj.EEType->IsICastable || !IsInstanceOfInterfaceViaICastable(obj, arrayElemType))
{
// Throw the array type mismatch exception defined by the classlib, using the input array's
// EEType* to find the correct classlib.
IntPtr addr = array.EEType->GetAssociatedModuleAddress();
Exception e = EH.GetClasslibException(ExceptionIDs.ArrayTypeMismatch, addr);
BinderIntrinsics.TailCall_RhpThrowEx(e);
}
}
// Both bounds and type check are ok.
fixed (void* pArray = &array.m_pEEType)
{
RhpAssignRef((IntPtr*)pArray + ArrayBaseIndex + index, obj);
}
}
else
{
fixed (void * pArray = &array.m_pEEType)
{
// Storing null does not require write barrier
*((IntPtr*)pArray + ArrayBaseIndex + index) = default(IntPtr);
}
}
}
示例2: StelemRef
static public unsafe void StelemRef(Object array, int index, object obj)
{
// This is supported only on arrays
Debug.Assert(array.EEType->IsArray, "first argument must be an array");
if (index >= array.GetArrayLength())
{
IntPtr addr = array.EEType->GetAssociatedModuleAddress();
Exception e = EH.GetClasslibException(ExceptionIDs.IndexOutOfRange, addr);
throw e;
}
if (obj != null)
{
EEType* arrayElemType = array.EEType->RelatedParameterType;
bool compatible;
if (arrayElemType->IsInterface)
{
compatible = IsInstanceOfInterface(obj, arrayElemType) != null;
}
else if (arrayElemType->IsArray)
{
compatible = IsInstanceOfArray(obj, arrayElemType) != null;
}
else
{
compatible = IsInstanceOfClass(obj, arrayElemType) != null;
}
if (!compatible)
{
// Throw the array type mismatch exception defined by the classlib, using the input array's EEType*
// to find the correct classlib.
IntPtr addr = array.EEType->GetAssociatedModuleAddress();
Exception e = EH.GetClasslibException(ExceptionIDs.ArrayTypeMismatch, addr);
BinderIntrinsics.TailCall_RhpThrowEx(e);
}
// Both bounds and type check are ok.
fixed (void * pArray = &array.m_pEEType)
{
RhpAssignRef((IntPtr*)pArray + ArrayBaseIndex + index, obj);
}
}
else
{
fixed (void * pArray = &array.m_pEEType)
{
// Storing null does not require write barrier
*((IntPtr*)pArray + ArrayBaseIndex + index) = default(IntPtr);
}
}
}