当前位置: 首页>>代码示例>>C#>>正文


C# Object.GetArrayLength方法代码示例

本文整理汇总了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);
                }
            }
        }
开发者ID:mjp41,项目名称:corert,代码行数:47,代码来源:TypeCast.cs

示例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);
                }
            }
        }
开发者ID:Priya91,项目名称:corert,代码行数:55,代码来源:TypeCast.cs


注:本文中的Object.GetArrayLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。