Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / ArraySegment.cs / 1305376 / 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; using System.Diagnostics.Contracts; 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"); Contract.EndContractBlock(); _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")); Contract.EndContractBlock(); _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); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // 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; using System.Diagnostics.Contracts; 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"); Contract.EndContractBlock(); _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")); Contract.EndContractBlock(); _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); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- OleStrCAMarshaler.cs
- DataGridViewImageCell.cs
- RemoteWebConfigurationHostStream.cs
- BrushMappingModeValidation.cs
- FrameworkElementFactoryMarkupObject.cs
- DoubleLinkList.cs
- KoreanLunisolarCalendar.cs
- HtmlInputPassword.cs
- MemberProjectedSlot.cs
- QueryInterceptorAttribute.cs
- Int32Collection.cs
- SmiMetaData.cs
- DBDataPermission.cs
- InvalidCastException.cs
- DataListCommandEventArgs.cs
- RuleEngine.cs
- SendSecurityHeaderElement.cs
- UnsafeNativeMethods.cs
- DataGridViewHeaderCell.cs
- IODescriptionAttribute.cs
- FactoryRecord.cs
- GlobalAclOperationRequirement.cs
- DialogDivider.cs
- WeakReferenceList.cs
- IItemContainerGenerator.cs
- XmlDomTextWriter.cs
- DataView.cs
- TreeWalkHelper.cs
- ToolStrip.cs
- IgnoreDeviceFilterElementCollection.cs
- Literal.cs
- CollectionBase.cs
- XmlCountingReader.cs
- Registry.cs
- DataGridBoundColumn.cs
- AsmxEndpointPickerExtension.cs
- MessageDecoder.cs
- RoleGroup.cs
- DecimalKeyFrameCollection.cs
- PagesChangedEventArgs.cs
- TextEditorLists.cs
- StaticSiteMapProvider.cs
- TextTreeRootNode.cs
- lengthconverter.cs
- SQLResource.cs
- TransformGroup.cs
- TimelineClockCollection.cs
- JsonClassDataContract.cs
- Color.cs
- SmiMetaData.cs
- EntitySqlException.cs
- RotationValidation.cs
- ConfigurationLocationCollection.cs
- StrongNamePublicKeyBlob.cs
- XmlDataImplementation.cs
- XMLUtil.cs
- TimeoutHelper.cs
- LinkDescriptor.cs
- KnownIds.cs
- TrackBarDesigner.cs
- LifetimeServices.cs
- Pipe.cs
- LinqDataSourceUpdateEventArgs.cs
- TableLayoutStyleCollection.cs
- HighlightComponent.cs
- SqlNotificationEventArgs.cs
- ReferencedCollectionType.cs
- NullReferenceException.cs
- CreateUserWizard.cs
- PlainXmlWriter.cs
- shaperfactoryquerycachekey.cs
- TreeNodeEventArgs.cs
- CmsInterop.cs
- LinearKeyFrames.cs
- SafeLocalAllocation.cs
- SrgsToken.cs
- EmptyEnumerator.cs
- InvalidAsynchronousStateException.cs
- DropAnimation.xaml.cs
- TypeGeneratedEventArgs.cs
- HotCommands.cs
- TextElementCollection.cs
- JavaScriptSerializer.cs
- CommonRemoteMemoryBlock.cs
- WebPartManager.cs
- LeaseManager.cs
- Bits.cs
- XamlPathDataSerializer.cs
- BevelBitmapEffect.cs
- MailBnfHelper.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- WebPartDisplayModeCancelEventArgs.cs
- Adorner.cs
- ProviderConnectionPoint.cs
- connectionpool.cs
- BindValidationContext.cs
- EventListenerClientSide.cs
- ContentHostHelper.cs
- CodePropertyReferenceExpression.cs
- WebPartConnectionsEventArgs.cs