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
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- OptionUsage.cs
- RijndaelManagedTransform.cs
- PackagePart.cs
- ParameterCollection.cs
- SplitterCancelEvent.cs
- DataRelationPropertyDescriptor.cs
- ReadOnlyPropertyMetadata.cs
- RenderDataDrawingContext.cs
- CurrentTimeZone.cs
- BitmapImage.cs
- ComboBoxRenderer.cs
- ResourceSet.cs
- KeysConverter.cs
- DataGridViewColumnCollectionDialog.cs
- MenuItem.cs
- SubclassTypeValidatorAttribute.cs
- SwitchAttribute.cs
- Attributes.cs
- DurableEnlistmentState.cs
- InputLanguageCollection.cs
- DeferredSelectedIndexReference.cs
- ServiceNameCollection.cs
- EnumUnknown.cs
- EntityDataSourceSelectingEventArgs.cs
- NavigationPropertyEmitter.cs
- DBSqlParserColumnCollection.cs
- ObjectListTitleAttribute.cs
- ImmutableObjectAttribute.cs
- RequestSecurityTokenResponseCollection.cs
- AppDomain.cs
- ToolboxDataAttribute.cs
- OptimalBreakSession.cs
- TcpProcessProtocolHandler.cs
- recordstatefactory.cs
- MultiSelector.cs
- RegionData.cs
- Enumerable.cs
- InstanceKeyNotReadyException.cs
- SafeNativeMethods.cs
- DescendentsWalker.cs
- TypeSystemHelpers.cs
- TcpChannelFactory.cs
- ServiceHostFactory.cs
- TableDetailsRow.cs
- ProcessThread.cs
- SyndicationItem.cs
- entitydatasourceentitysetnameconverter.cs
- VirtualDirectoryMappingCollection.cs
- EFDataModelProvider.cs
- Geometry.cs
- DateTimeOffsetStorage.cs
- BinaryReader.cs
- GenericWebPart.cs
- TraceListeners.cs
- Debug.cs
- SmtpReplyReader.cs
- HttpCookie.cs
- JournalNavigationScope.cs
- MemberRelationshipService.cs
- AccessDataSourceDesigner.cs
- Missing.cs
- SmtpNtlmAuthenticationModule.cs
- MethodCallTranslator.cs
- InstalledVoice.cs
- WorkflowIdleElement.cs
- WebBrowserDocumentCompletedEventHandler.cs
- FaultConverter.cs
- BrowserCapabilitiesFactory.cs
- State.cs
- SpellerStatusTable.cs
- XPathBinder.cs
- MatrixStack.cs
- StreamReader.cs
- ResourceIDHelper.cs
- MergablePropertyAttribute.cs
- ObjectAnimationUsingKeyFrames.cs
- ContactManager.cs
- ColumnTypeConverter.cs
- DynamicPropertyHolder.cs
- RuleProcessor.cs
- XslAst.cs
- TemplateBindingExtensionConverter.cs
- TextWriterTraceListener.cs
- BamlRecordWriter.cs
- TextViewBase.cs
- MD5CryptoServiceProvider.cs
- BooleanProjectedSlot.cs
- TreeViewDesigner.cs
- DataGridViewCellEventArgs.cs
- DebugInfoExpression.cs
- RepeatButtonAutomationPeer.cs
- _BasicClient.cs
- BatchParser.cs
- DetailsViewUpdateEventArgs.cs
- ClientConfigPaths.cs
- XPathNodePointer.cs
- ConfigViewGenerator.cs
- ListControl.cs
- PreviewPageInfo.cs
- IntegerCollectionEditor.cs