Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / untmp / whidbey / QFE / 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); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- NamedElement.cs
- PositiveTimeSpanValidatorAttribute.cs
- XmlIncludeAttribute.cs
- LoadItemsEventArgs.cs
- ConfigXmlSignificantWhitespace.cs
- SqlClientFactory.cs
- Propagator.cs
- DateTimeParse.cs
- ListViewGroupCollectionEditor.cs
- MouseButtonEventArgs.cs
- _AuthenticationState.cs
- TabPage.cs
- smtpconnection.cs
- BrowserCapabilitiesCompiler.cs
- NameScope.cs
- Matrix3DConverter.cs
- SpellerStatusTable.cs
- DbParameterCollectionHelper.cs
- XmlSortKeyAccumulator.cs
- SiteOfOriginContainer.cs
- View.cs
- BlockCollection.cs
- TreeViewHitTestInfo.cs
- UpdateCommand.cs
- ReadOnlyAttribute.cs
- TreePrinter.cs
- VirtualizedItemProviderWrapper.cs
- CellCreator.cs
- SectionInformation.cs
- ToolboxItemCollection.cs
- MediaTimeline.cs
- CodeStatementCollection.cs
- CustomTokenProvider.cs
- PatternMatcher.cs
- JavaScriptString.cs
- SoapParser.cs
- SystemIPAddressInformation.cs
- EventLogEntry.cs
- InputScope.cs
- KeyedHashAlgorithm.cs
- TimeSpanConverter.cs
- AlgoModule.cs
- ArrayHelper.cs
- HttpGetProtocolReflector.cs
- ElementNotEnabledException.cs
- WebHeaderCollection.cs
- XhtmlConformanceSection.cs
- SourceSwitch.cs
- PriorityQueue.cs
- InertiaTranslationBehavior.cs
- ProcessProtocolHandler.cs
- MessageSmuggler.cs
- XmlSchemaInferenceException.cs
- CategoryAttribute.cs
- mactripleDES.cs
- JsonObjectDataContract.cs
- ClientRolePrincipal.cs
- XmlChildNodes.cs
- DATA_BLOB.cs
- ImageField.cs
- TextBoxView.cs
- PreviewControlDesigner.cs
- SetIterators.cs
- Timer.cs
- IChannel.cs
- CodeTryCatchFinallyStatement.cs
- DataGridTablesFactory.cs
- WebEventTraceProvider.cs
- DoubleCollection.cs
- AsyncStreamReader.cs
- uribuilder.cs
- TextStore.cs
- MediaPlayer.cs
- DoubleLinkList.cs
- CodeAttachEventStatement.cs
- KeySplineConverter.cs
- Point4D.cs
- CopyCodeAction.cs
- TableLayoutPanelBehavior.cs
- SchemaImporterExtensionElementCollection.cs
- SyndicationDeserializer.cs
- Win32.cs
- SqlXml.cs
- XmlNotation.cs
- TargetConverter.cs
- ClientRuntimeConfig.cs
- X509CertificateClaimSet.cs
- ArgumentException.cs
- MsmqIntegrationInputChannel.cs
- ScriptingAuthenticationServiceSection.cs
- DBNull.cs
- HealthMonitoringSection.cs
- RegexTree.cs
- SelectedDatesCollection.cs
- SiteMapSection.cs
- _HelperAsyncResults.cs
- TransformPattern.cs
- MobilePage.cs
- MissingMethodException.cs
- EntityModelSchemaGenerator.cs