Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PanelDesigner.cs
- DataTable.cs
- TextRangeSerialization.cs
- ArithmeticException.cs
- Main.cs
- DiscoveryEndpointElement.cs
- PathSegmentCollection.cs
- UriGenerator.cs
- TextEditorDragDrop.cs
- TemplateParser.cs
- SemanticTag.cs
- SelectionItemProviderWrapper.cs
- CLRBindingWorker.cs
- OutOfProcStateClientManager.cs
- HtmlTableCellCollection.cs
- WebPartConnectionsCloseVerb.cs
- StrongTypingException.cs
- MethodExpression.cs
- FilterException.cs
- TrackPointCollection.cs
- CommandValueSerializer.cs
- SafeEventLogReadHandle.cs
- GACIdentityPermission.cs
- webproxy.cs
- BookmarkCallbackWrapper.cs
- cache.cs
- TimeZone.cs
- Transform3D.cs
- StackSpiller.Generated.cs
- SafeRightsManagementSessionHandle.cs
- clipboard.cs
- XmlQuerySequence.cs
- EntityModelSchemaGenerator.cs
- GPPOINT.cs
- SocketException.cs
- FormViewPageEventArgs.cs
- SafeRegistryHandle.cs
- TextServicesDisplayAttributePropertyRanges.cs
- JournalEntryStack.cs
- MILUtilities.cs
- GetPageNumberCompletedEventArgs.cs
- ToolStripComboBox.cs
- SoapInteropTypes.cs
- XmlConvert.cs
- PrintPreviewDialog.cs
- TypeUsage.cs
- SamlAttribute.cs
- GroupAggregateExpr.cs
- InternalConfigEventArgs.cs
- AutomationPeer.cs
- WorkerProcess.cs
- ActivationServices.cs
- XhtmlBasicLiteralTextAdapter.cs
- KnownAssembliesSet.cs
- MexHttpsBindingCollectionElement.cs
- SecurityCookieModeValidator.cs
- SQLChars.cs
- SQLBinaryStorage.cs
- Vector3DValueSerializer.cs
- CodeAttributeDeclarationCollection.cs
- SqlUdtInfo.cs
- DataSet.cs
- ResourceReader.cs
- QuaternionKeyFrameCollection.cs
- SyntaxCheck.cs
- TableLayoutSettingsTypeConverter.cs
- OdbcConnectionPoolProviderInfo.cs
- ExecutionEngineException.cs
- ComplexPropertyEntry.cs
- unitconverter.cs
- XPathMultyIterator.cs
- SchemaTableColumn.cs
- BitmapEffect.cs
- InvokeWebService.cs
- HuffModule.cs
- ResourceDefaultValueAttribute.cs
- Page.cs
- SafeFileMappingHandle.cs
- ContentFilePart.cs
- GlobalizationSection.cs
- RIPEMD160.cs
- XmlUtf8RawTextWriter.cs
- BoundColumn.cs
- ResourceExpressionBuilder.cs
- ADMembershipUser.cs
- DataRelationPropertyDescriptor.cs
- UpnEndpointIdentity.cs
- DefaultValueConverter.cs
- XamlSerializerUtil.cs
- ComplexObject.cs
- UnknownBitmapEncoder.cs
- LabelInfo.cs
- xamlnodes.cs
- FormViewAutoFormat.cs
- remotingproxy.cs
- MemoryMappedViewStream.cs
- AttributeConverter.cs
- ColorBlend.cs
- SymbolUsageManager.cs
- SoapInteropTypes.cs