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
- SourceFileInfo.cs
- XmlChildEnumerator.cs
- WebRequestModulesSection.cs
- MobileControlBuilder.cs
- HtmlTable.cs
- ExecutionEngineException.cs
- bindurihelper.cs
- RtType.cs
- QueryCacheManager.cs
- SimpleHandlerBuildProvider.cs
- AuditLevel.cs
- WindowsRichEdit.cs
- CodePageEncoding.cs
- ListCollectionView.cs
- QueueProcessor.cs
- CalendarButton.cs
- DynamicEntity.cs
- DataList.cs
- ConfigsHelper.cs
- MD5HashHelper.cs
- XmlDocument.cs
- XmlElementCollection.cs
- BuildProviderCollection.cs
- PeerInputChannel.cs
- EnvelopedPkcs7.cs
- CancellationHandler.cs
- IEnumerable.cs
- _NestedSingleAsyncResult.cs
- CalendarDateChangedEventArgs.cs
- PageOutputColor.cs
- MimeObjectFactory.cs
- AssemblySettingAttributes.cs
- BitmapMetadataEnumerator.cs
- RichTextBox.cs
- Zone.cs
- EdmScalarPropertyAttribute.cs
- ColorComboBox.cs
- BaseResourcesBuildProvider.cs
- DataServiceQuery.cs
- WrappedDispatcherException.cs
- ToolStripItemClickedEventArgs.cs
- AttributeCollection.cs
- OdbcConnection.cs
- SecurityPermission.cs
- PersonalizationProvider.cs
- RawUIStateInputReport.cs
- Speller.cs
- Image.cs
- SelectionRange.cs
- Attributes.cs
- ProfileManager.cs
- NativeMethods.cs
- TypeToken.cs
- AdornerDecorator.cs
- SchemaObjectWriter.cs
- EdgeModeValidation.cs
- WebPartTransformerCollection.cs
- CodeMethodReturnStatement.cs
- SettingsAttributes.cs
- CodeTypeParameterCollection.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- OdbcConnectionString.cs
- ActionMessageFilter.cs
- Style.cs
- SystemFonts.cs
- HttpValueCollection.cs
- XMLUtil.cs
- PropertyBuilder.cs
- DataGridViewColumnEventArgs.cs
- DataStorage.cs
- SQLCharsStorage.cs
- CaseCqlBlock.cs
- OracleConnectionFactory.cs
- StronglyTypedResourceBuilder.cs
- SqlRewriteScalarSubqueries.cs
- Command.cs
- SmiSettersStream.cs
- NativeMethodsOther.cs
- TimestampInformation.cs
- UIElement3DAutomationPeer.cs
- HelpEvent.cs
- TextBounds.cs
- RoleService.cs
- InstanceHandleConflictException.cs
- StrokeSerializer.cs
- CharEnumerator.cs
- SpeechRecognizer.cs
- WebConfigurationManager.cs
- SID.cs
- BufferModesCollection.cs
- HttpClientProtocol.cs
- MethodExecutor.cs
- ResourceAttributes.cs
- ParameterReplacerVisitor.cs
- ClientConfigurationSystem.cs
- RuleSettings.cs
- TreeBuilderBamlTranslator.cs
- ContextTokenTypeConverter.cs
- ProcessModuleCollection.cs
- ColumnHeader.cs