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
- AmbientValueAttribute.cs
- MetaModel.cs
- EditingCoordinator.cs
- SqlWorkflowInstanceStore.cs
- ObjectMemberMapping.cs
- PageThemeBuildProvider.cs
- TimeStampChecker.cs
- Material.cs
- MulticastIPAddressInformationCollection.cs
- TrimSurroundingWhitespaceAttribute.cs
- ContextProperty.cs
- NumberFormatter.cs
- AuthenticationSection.cs
- WsdlBuildProvider.cs
- BitmapEffectDrawing.cs
- ToolStripSettings.cs
- ShapeTypeface.cs
- SqlErrorCollection.cs
- DrawListViewSubItemEventArgs.cs
- ConnectionStringEditor.cs
- Classification.cs
- OletxResourceManager.cs
- ServerIdentity.cs
- TypeUtil.cs
- ExpressionUtilities.cs
- SelectManyQueryOperator.cs
- RuleProcessor.cs
- RegexCode.cs
- Fonts.cs
- ComplexTypeEmitter.cs
- EntityContainerRelationshipSet.cs
- XmlWrappingReader.cs
- SecUtil.cs
- RootDesignerSerializerAttribute.cs
- LinqDataSourceSelectEventArgs.cs
- BindingManagerDataErrorEventArgs.cs
- EntityContainer.cs
- PointHitTestParameters.cs
- StylusPointCollection.cs
- NumberAction.cs
- StreamResourceInfo.cs
- TableLayoutSettingsTypeConverter.cs
- SapiRecoContext.cs
- QueryStoreStatusRequest.cs
- X509Utils.cs
- SQLByteStorage.cs
- ConsoleKeyInfo.cs
- InvalidWMPVersionException.cs
- FtpWebResponse.cs
- util.cs
- GridViewItemAutomationPeer.cs
- ChunkedMemoryStream.cs
- BinarySerializer.cs
- FactoryGenerator.cs
- EntityConnectionStringBuilder.cs
- TableRowCollection.cs
- GeometryModel3D.cs
- DeclarativeCatalogPart.cs
- SamlAttributeStatement.cs
- DelegatingMessage.cs
- MessageQueueKey.cs
- CatalogPart.cs
- OutKeywords.cs
- GeometryModel3D.cs
- XmlDataProvider.cs
- DataService.cs
- RoleService.cs
- BamlMapTable.cs
- IPEndPoint.cs
- SerializeAbsoluteContext.cs
- CodeSnippetStatement.cs
- InvokePatternIdentifiers.cs
- ClrPerspective.cs
- HandlerFactoryWrapper.cs
- DatatypeImplementation.cs
- CodeMethodInvokeExpression.cs
- ListBoxAutomationPeer.cs
- ChildChangedEventArgs.cs
- arc.cs
- CodeEventReferenceExpression.cs
- Identifier.cs
- ToolStripProfessionalLowResolutionRenderer.cs
- RoleGroupCollection.cs
- AnnotationResourceCollection.cs
- NonceCache.cs
- MsmqIntegrationValidationBehavior.cs
- InstanceCreationEditor.cs
- Simplifier.cs
- ProfileGroupSettings.cs
- UTF8Encoding.cs
- OdbcConnectionStringbuilder.cs
- GlobalAllocSafeHandle.cs
- embossbitmapeffect.cs
- SvcMapFile.cs
- AssemblyNameProxy.cs
- ControlBindingsCollection.cs
- Attributes.cs
- SafeWaitHandle.cs
- SqlServices.cs
- CommandConverter.cs