Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / clr / src / BCL / System / ArraySegment.cs / 1 / ArraySegment.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: ArraySegment** ** ** Purpose: Convenient wrapper for an array, an offset, and ** a count. Ideally used in streams & collections. ** Net Classes will consume an array of these. ** ** ===========================================================*/ using System.Runtime.InteropServices; namespace System { [Serializable] public struct ArraySegment { private T[] _array; private int _offset; private int _count; public ArraySegment(T[] array) { if (array == null) throw new ArgumentNullException("array"); _array = array; _offset = 0; _count = array.Length; } public ArraySegment(T[] array, int offset, int count) { if (array == null) throw new ArgumentNullException("array"); if (offset < 0) throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (array.Length - offset < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); _array = array; _offset = offset; _count = count; } public T[] Array { get { return _array; } } public int Offset { get { return _offset; } } public int Count { get { return _count; } } public override int GetHashCode() { return _array.GetHashCode() ^ _offset ^ _count; } public override bool Equals(Object obj) { if (obj is ArraySegment ) return Equals((ArraySegment )obj); else return false; } public bool Equals(ArraySegment obj) { return obj._array == _array && obj._offset == _offset && obj._count == _count; } public static bool operator ==(ArraySegment a, ArraySegment b) { return a.Equals(b); } public static bool operator !=(ArraySegment a, ArraySegment b) { return !(a == b); } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AsyncCompletedEventArgs.cs
- ReadOnlyDictionary.cs
- CommandPlan.cs
- SelectedGridItemChangedEvent.cs
- TextAnchor.cs
- AssemblyHash.cs
- DependencyPropertyHelper.cs
- PrePostDescendentsWalker.cs
- bindurihelper.cs
- HierarchicalDataSourceControl.cs
- TextEditorMouse.cs
- ErrorCodes.cs
- DateRangeEvent.cs
- CompositionTarget.cs
- StylusCollection.cs
- PolyQuadraticBezierSegment.cs
- TraceData.cs
- DataGridDefaultColumnWidthTypeConverter.cs
- SafeHandles.cs
- CodeMemberProperty.cs
- SingleAnimationUsingKeyFrames.cs
- XmlWriterTraceListener.cs
- CoreSwitches.cs
- DataControlButton.cs
- TypeElement.cs
- Point4DValueSerializer.cs
- Substitution.cs
- HtmlEncodedRawTextWriter.cs
- DelegateTypeInfo.cs
- InkCollectionBehavior.cs
- XmlSchemaComplexContentRestriction.cs
- BoundingRectTracker.cs
- NativeMethods.cs
- PageThemeBuildProvider.cs
- Panel.cs
- GeometryHitTestResult.cs
- BamlRecordHelper.cs
- DESCryptoServiceProvider.cs
- ThicknessAnimationBase.cs
- ServiceThrottlingBehavior.cs
- RootProfilePropertySettingsCollection.cs
- MethodCallExpression.cs
- ReceiveReply.cs
- GridViewPageEventArgs.cs
- UICuesEvent.cs
- AccessedThroughPropertyAttribute.cs
- ZipIOLocalFileBlock.cs
- AutomationPeer.cs
- ListSortDescription.cs
- GPRECT.cs
- LicenseContext.cs
- DataTemplateKey.cs
- Logging.cs
- SerialPort.cs
- RepeatButtonAutomationPeer.cs
- TransformerTypeCollection.cs
- CmsInterop.cs
- DocumentSequence.cs
- _SslSessionsCache.cs
- VBCodeProvider.cs
- Missing.cs
- ResourceDescriptionAttribute.cs
- Stream.cs
- MsmqMessageProperty.cs
- Operator.cs
- MarkerProperties.cs
- PageRequestManager.cs
- StrongNameMembershipCondition.cs
- MetadataFile.cs
- SiteMap.cs
- TriggerBase.cs
- EditCommandColumn.cs
- Aggregates.cs
- WebBrowserBase.cs
- EntityDataSourceDesigner.cs
- ScriptRegistrationManager.cs
- TagPrefixInfo.cs
- ValidatingReaderNodeData.cs
- PhysicalFontFamily.cs
- AdjustableArrowCap.cs
- DLinqColumnProvider.cs
- serverconfig.cs
- OdbcParameterCollection.cs
- SchemaDeclBase.cs
- PointCollectionConverter.cs
- WebDisplayNameAttribute.cs
- FilteredDataSetHelper.cs
- IDQuery.cs
- SystemIPAddressInformation.cs
- UdpDiscoveryEndpointProvider.cs
- TabControlEvent.cs
- KerberosTicketHashIdentifierClause.cs
- HotSpotCollection.cs
- EventLogEntryCollection.cs
- ReferentialConstraint.cs
- KeyboardInputProviderAcquireFocusEventArgs.cs
- EncryptedKey.cs
- TemplateNameScope.cs
- TransportConfigurationTypeElement.cs
- MutexSecurity.cs