Code:
/ DotNET / DotNET / 8.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
- EntityViewGenerator.cs
- OutOfMemoryException.cs
- CryptoHandle.cs
- FixedSOMGroup.cs
- AnimationStorage.cs
- CompositeActivityDesigner.cs
- MenuCommand.cs
- FontFamilyValueSerializer.cs
- DirtyTextRange.cs
- BitmapEffectvisualstate.cs
- COM2PictureConverter.cs
- Compiler.cs
- PageContent.cs
- NativeMethods.cs
- SingleConverter.cs
- Transform.cs
- Geometry.cs
- AngleUtil.cs
- RegionIterator.cs
- ObjectSecurityT.cs
- NetworkInterface.cs
- ParsedAttributeCollection.cs
- TabControl.cs
- ObjectQueryState.cs
- DbParameterCollectionHelper.cs
- ArrayEditor.cs
- WindowsUpDown.cs
- InputLanguageManager.cs
- SecurityPolicySection.cs
- TypedAsyncResult.cs
- PageThemeParser.cs
- ConfigXmlText.cs
- ObjectDataSourceChooseMethodsPanel.cs
- GetIsBrowserClientRequest.cs
- HttpProcessUtility.cs
- TrustSection.cs
- DefaultTextStore.cs
- NetCodeGroup.cs
- ScriptManager.cs
- SharedUtils.cs
- JsonFormatReaderGenerator.cs
- WebPartMovingEventArgs.cs
- LinqDataSourceDeleteEventArgs.cs
- ComponentChangingEvent.cs
- KnownIds.cs
- EventRoute.cs
- MonthChangedEventArgs.cs
- NativeWindow.cs
- AmbientLight.cs
- PriorityBinding.cs
- QueryOutputWriter.cs
- RemotingConfigParser.cs
- TextElementCollectionHelper.cs
- ConnectionPoolManager.cs
- TTSEvent.cs
- TextTreeRootTextBlock.cs
- HwndProxyElementProvider.cs
- ZoneLinkButton.cs
- CustomValidator.cs
- DataGridViewColumnEventArgs.cs
- ColorConvertedBitmapExtension.cs
- ContainerVisual.cs
- TableLayoutPanelCellPosition.cs
- COAUTHINFO.cs
- IPGlobalProperties.cs
- StylusPointDescription.cs
- TextServicesCompartment.cs
- TreeViewAutomationPeer.cs
- SiteMapNodeCollection.cs
- WorkflowOwnerAsyncResult.cs
- PasswordValidationException.cs
- DataGridDesigner.cs
- CompilerLocalReference.cs
- ServicePointManagerElement.cs
- HostElement.cs
- DbConnectionStringBuilder.cs
- Header.cs
- SourceChangedEventArgs.cs
- ItemMap.cs
- PasswordBoxAutomationPeer.cs
- BuildProvidersCompiler.cs
- XMLDiffLoader.cs
- PersistChildrenAttribute.cs
- DataTransferEventArgs.cs
- ToolTip.cs
- Debug.cs
- MaskedTextProvider.cs
- TreeNode.cs
- ReturnEventArgs.cs
- filewebrequest.cs
- SourceChangedEventArgs.cs
- CaseInsensitiveComparer.cs
- HtmlFormAdapter.cs
- Crc32.cs
- MetafileHeaderWmf.cs
- ActivitySurrogate.cs
- BitmapEffectDrawingContent.cs
- SafeNativeMethods.cs
- DataProviderNameConverter.cs
- ProfileEventArgs.cs