Code:
/ 4.0 / 4.0 / 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. // ==++== // // 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
- RawContentTypeMapper.cs
- EnlistmentTraceIdentifier.cs
- TableHeaderCell.cs
- _FtpDataStream.cs
- PathGeometry.cs
- VectorAnimation.cs
- DeflateStreamAsyncResult.cs
- QueryContinueDragEventArgs.cs
- ExtensionDataObject.cs
- DiscreteKeyFrames.cs
- webbrowsersite.cs
- DataGridViewColumn.cs
- Rotation3DKeyFrameCollection.cs
- SplitterEvent.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- SoapHttpTransportImporter.cs
- TrustLevel.cs
- RunClient.cs
- TrustSection.cs
- RuntimeResourceSet.cs
- TemplateBindingExtensionConverter.cs
- ObjectDataSource.cs
- DefaultBindingPropertyAttribute.cs
- BmpBitmapDecoder.cs
- MsmqHostedTransportConfiguration.cs
- EntityProviderServices.cs
- COM2ComponentEditor.cs
- VectorAnimationBase.cs
- DebugViewWriter.cs
- Crypto.cs
- DESCryptoServiceProvider.cs
- PolicyManager.cs
- StreamGeometry.cs
- Serializer.cs
- ToolStripSystemRenderer.cs
- DataTemplateKey.cs
- HandleExceptionArgs.cs
- WindowsFormsSynchronizationContext.cs
- PEFileEvidenceFactory.cs
- NotifyInputEventArgs.cs
- CodeLabeledStatement.cs
- AdapterUtil.cs
- SqlDataSourceQuery.cs
- ToolStripOverflow.cs
- ModelItemImpl.cs
- Size.cs
- ParserStack.cs
- TagPrefixCollection.cs
- BatchServiceHost.cs
- Triplet.cs
- ScriptResourceHandler.cs
- ProjectionPathBuilder.cs
- WebServiceHostFactory.cs
- _TransmitFileOverlappedAsyncResult.cs
- AdapterDictionary.cs
- PopupControlService.cs
- StatusBarPanelClickEvent.cs
- SmtpReplyReaderFactory.cs
- PlainXmlSerializer.cs
- ToolStripItemTextRenderEventArgs.cs
- x509utils.cs
- PageClientProxyGenerator.cs
- HelpKeywordAttribute.cs
- SingleAnimationUsingKeyFrames.cs
- EmbeddedMailObjectsCollection.cs
- PrePostDescendentsWalker.cs
- HelloOperation11AsyncResult.cs
- DataGridClipboardHelper.cs
- HandledMouseEvent.cs
- Regex.cs
- SkipStoryboardToFill.cs
- JournalEntryStack.cs
- HtmlFormParameterWriter.cs
- Section.cs
- PerformanceCounterLib.cs
- ListDataBindEventArgs.cs
- FilterableData.cs
- ComplexTypeEmitter.cs
- EventItfInfo.cs
- TimeStampChecker.cs
- SafeSystemMetrics.cs
- XmlILConstructAnalyzer.cs
- MexTcpBindingElement.cs
- DefaultValueTypeConverter.cs
- WindowsIdentity.cs
- ChangeDirector.cs
- XamlToRtfWriter.cs
- XsltQilFactory.cs
- WebPartZoneCollection.cs
- IEnumerable.cs
- AssertSection.cs
- DynamicFilter.cs
- LaxModeSecurityHeaderElementInferenceEngine.cs
- WebServiceMethodData.cs
- ContentFileHelper.cs
- HtmlShim.cs
- SessionStateSection.cs
- IDispatchConstantAttribute.cs
- DBDataPermission.cs
- CornerRadiusConverter.cs