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
- HelpPage.cs
- GroupQuery.cs
- CompositeControl.cs
- DefaultHttpHandler.cs
- Transform.cs
- EncryptedType.cs
- RegexInterpreter.cs
- CommandLibraryHelper.cs
- PropertyValueUIItem.cs
- SecurityException.cs
- AuthStoreRoleProvider.cs
- COM2Enum.cs
- AccessorTable.cs
- WeakEventTable.cs
- WaitHandleCannotBeOpenedException.cs
- _DisconnectOverlappedAsyncResult.cs
- FixedSOMLineCollection.cs
- ComponentResourceManager.cs
- EventBuilder.cs
- TemplateComponentConnector.cs
- PagerStyle.cs
- HelloMessageCD1.cs
- TextRange.cs
- WindowsMenu.cs
- PolicyException.cs
- OpCellTreeNode.cs
- CompressEmulationStream.cs
- StringFunctions.cs
- LinqDataSourceValidationException.cs
- coordinatorscratchpad.cs
- WebHttpBindingElement.cs
- XmlStreamedByteStreamReader.cs
- RuleRefElement.cs
- ButtonRenderer.cs
- EntityDataSourceDataSelection.cs
- FlowchartDesignerCommands.cs
- ExtensibleClassFactory.cs
- UdpSocketReceiveManager.cs
- SpeechUI.cs
- ContentValidator.cs
- ColorContextHelper.cs
- ComponentManagerBroker.cs
- DataKey.cs
- CompilationLock.cs
- LeafCellTreeNode.cs
- DecimalAnimation.cs
- ObjectParameterCollection.cs
- CacheSection.cs
- OutputCacheSettingsSection.cs
- MailMessageEventArgs.cs
- WindowsTokenRoleProvider.cs
- CompareValidator.cs
- HtmlFormWrapper.cs
- Int32CollectionConverter.cs
- DependencyPropertyConverter.cs
- HttpCachePolicy.cs
- Math.cs
- CompressStream.cs
- TextRunCache.cs
- Merger.cs
- LinkUtilities.cs
- StringWriter.cs
- CreateUserWizardStep.cs
- ColumnReorderedEventArgs.cs
- ApplicationDirectory.cs
- SpecialNameAttribute.cs
- SamlAttributeStatement.cs
- PrintEvent.cs
- basenumberconverter.cs
- DrawingGroupDrawingContext.cs
- RectAnimationUsingKeyFrames.cs
- PublishLicense.cs
- ReflectPropertyDescriptor.cs
- TransformCollection.cs
- DynamicHyperLink.cs
- EncodingInfo.cs
- OneOfScalarConst.cs
- BitmapFrameDecode.cs
- ThicknessAnimation.cs
- DynamicValidator.cs
- HttpProcessUtility.cs
- CharAnimationBase.cs
- DesignerCommandAdapter.cs
- DynamicMethod.cs
- XmlHierarchicalEnumerable.cs
- IDispatchConstantAttribute.cs
- FileDialogPermission.cs
- FaultException.cs
- DataBoundControlActionList.cs
- CompositeTypefaceMetrics.cs
- DoubleLinkListEnumerator.cs
- CompositeTypefaceMetrics.cs
- QilReference.cs
- BamlResourceContent.cs
- ExportException.cs
- NetworkInterface.cs
- TreeNodeClickEventArgs.cs
- Camera.cs
- Propagator.JoinPropagator.cs
- PolicyLevel.cs