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
- ColorMap.cs
- FilterableData.cs
- SiteIdentityPermission.cs
- DataGridViewSelectedCellCollection.cs
- HtmlElement.cs
- PreProcessInputEventArgs.cs
- RenameRuleObjectDialog.cs
- ArraySet.cs
- SignatureHelper.cs
- References.cs
- IntSecurity.cs
- Method.cs
- HtmlHead.cs
- BooleanExpr.cs
- WindowsFormsHostAutomationPeer.cs
- ListViewItem.cs
- WebBrowserPermission.cs
- SqlDataRecord.cs
- ResizingMessageFilter.cs
- DrawListViewColumnHeaderEventArgs.cs
- XmlSchemaGroupRef.cs
- CookieHandler.cs
- PeerNameRecordCollection.cs
- PopOutPanel.cs
- EntityDataSourceChangingEventArgs.cs
- ObjectItemLoadingSessionData.cs
- SkewTransform.cs
- HttpUnhandledOperationInvoker.cs
- MarkupProperty.cs
- UInt32Storage.cs
- FragmentNavigationEventArgs.cs
- VoiceSynthesis.cs
- ToolboxComponentsCreatingEventArgs.cs
- DataTablePropertyDescriptor.cs
- RenderingEventArgs.cs
- ThreadSafeList.cs
- EntityViewGenerator.cs
- Cursors.cs
- IERequestCache.cs
- HtmlHistory.cs
- BitmapFrameEncode.cs
- XLinq.cs
- IOException.cs
- View.cs
- TemplateBaseAction.cs
- Message.cs
- WS2007FederationHttpBinding.cs
- StylusEditingBehavior.cs
- ConnectionManagementElement.cs
- IntegerCollectionEditor.cs
- RectAnimationBase.cs
- InkCanvasSelectionAdorner.cs
- RequestValidator.cs
- FrameworkContentElement.cs
- OdbcHandle.cs
- XamlInterfaces.cs
- ComponentCollection.cs
- PrinterResolution.cs
- TypedReference.cs
- ServerTooBusyException.cs
- FieldMetadata.cs
- DirectoryInfo.cs
- OneOfScalarConst.cs
- ProtocolElementCollection.cs
- IIS7ConfigurationLoader.cs
- DnsElement.cs
- TextDecorationCollection.cs
- TiffBitmapEncoder.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- HtmlGenericControl.cs
- StatusCommandUI.cs
- CompleteWizardStep.cs
- SetterBaseCollection.cs
- StorageComplexTypeMapping.cs
- Regex.cs
- DbXmlEnabledProviderManifest.cs
- DataTableMappingCollection.cs
- InterleavedZipPartStream.cs
- LinqDataSourceValidationException.cs
- EventLogTraceListener.cs
- ThrowHelper.cs
- ProxyElement.cs
- CodeGenHelper.cs
- RuleConditionDialog.cs
- Vector3dCollection.cs
- HtmlInputRadioButton.cs
- SingleTagSectionHandler.cs
- WorkflowOperationErrorHandler.cs
- AppDomainUnloadedException.cs
- DataGridParentRows.cs
- KeyedCollection.cs
- SafeUserTokenHandle.cs
- DbMetaDataFactory.cs
- NonClientArea.cs
- BinaryMethodMessage.cs
- StateWorkerRequest.cs
- SafeCryptContextHandle.cs
- WindowsComboBox.cs
- _KerberosClient.cs
- RegexParser.cs