Code:
/ FX-1434 / FX-1434 / 1.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
- MetadataArtifactLoaderCompositeFile.cs
- ColumnClickEvent.cs
- SoapTypeAttribute.cs
- ConnectionConsumerAttribute.cs
- WorkflowOperationErrorHandler.cs
- SchemaManager.cs
- UnsafeNativeMethods.cs
- PageThemeParser.cs
- NativeMethods.cs
- CacheOutputQuery.cs
- _DisconnectOverlappedAsyncResult.cs
- StorageTypeMapping.cs
- PerspectiveCamera.cs
- WindowsServiceElement.cs
- ReadOnlyActivityGlyph.cs
- QilCloneVisitor.cs
- XmlSchemaObject.cs
- X509RecipientCertificateClientElement.cs
- HostingEnvironmentException.cs
- AssemblyUtil.cs
- TransformerConfigurationWizardBase.cs
- SourceSwitch.cs
- BitmapMetadataBlob.cs
- TabPanel.cs
- ListViewHitTestInfo.cs
- XmlDocumentSurrogate.cs
- MailSettingsSection.cs
- XmlAttributeCollection.cs
- CounterSample.cs
- RegularExpressionValidator.cs
- VerticalAlignConverter.cs
- UInt16.cs
- UnsettableComboBox.cs
- CustomErrorsSectionWrapper.cs
- NeutralResourcesLanguageAttribute.cs
- ToolBar.cs
- DynamicDataResources.Designer.cs
- PackageRelationshipCollection.cs
- SspiHelper.cs
- PartialArray.cs
- XLinq.cs
- RegexRunnerFactory.cs
- SecurityDocument.cs
- ImageListStreamer.cs
- DataGridCellEditEndingEventArgs.cs
- HttpException.cs
- FixedHighlight.cs
- DataControlButton.cs
- SafeViewOfFileHandle.cs
- SymDocumentType.cs
- IArgumentProvider.cs
- ConnectionPointCookie.cs
- ToolStripPanelCell.cs
- Bezier.cs
- SizeConverter.cs
- BitmapMetadataEnumerator.cs
- EndpointDiscoveryMetadata11.cs
- SqlRetyper.cs
- DefaultDiscoveryService.cs
- SimpleWebHandlerParser.cs
- Brush.cs
- RelationshipSet.cs
- Context.cs
- InvalidCastException.cs
- ApplyImportsAction.cs
- Group.cs
- CachedFontFamily.cs
- WS2007HttpBindingCollectionElement.cs
- RowToParametersTransformer.cs
- HtmlInputReset.cs
- ServerValidateEventArgs.cs
- HttpEncoder.cs
- ForwardPositionQuery.cs
- Vector3DValueSerializer.cs
- WindowsUserNameSecurityTokenAuthenticator.cs
- PolyLineSegment.cs
- Overlapped.cs
- GlobalDataBindingHandler.cs
- XmlSerializationGeneratedCode.cs
- XPathConvert.cs
- BrowserInteropHelper.cs
- XmlBindingWorker.cs
- LoopExpression.cs
- Application.cs
- TreeNodeSelectionProcessor.cs
- WebPartAuthorizationEventArgs.cs
- ItemChangedEventArgs.cs
- ManagedCodeMarkers.cs
- MenuItemBindingCollection.cs
- ConsoleKeyInfo.cs
- SafePEFileHandle.cs
- LinkLabelLinkClickedEvent.cs
- StatusBar.cs
- EntitySetDataBindingList.cs
- SystemFonts.cs
- NestPullup.cs
- SafeNativeMethods.cs
- PageVisual.cs
- UpdatePanelTriggerCollection.cs
- DetailsViewRow.cs