Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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. // // ==--== /*============================================================ ** ** 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DBPropSet.cs
- LayoutInformation.cs
- SmtpDigestAuthenticationModule.cs
- TextTreeExtractElementUndoUnit.cs
- CatalogPartCollection.cs
- ToolStripDropDownButton.cs
- Transform.cs
- WizardStepBase.cs
- HttpProtocolReflector.cs
- NativeCppClassAttribute.cs
- ModelMemberCollection.cs
- ExpressionCopier.cs
- SrgsRuleRef.cs
- itemelement.cs
- TriggerBase.cs
- ContentControl.cs
- SafeTimerHandle.cs
- InheritanceContextChangedEventManager.cs
- ErrorItem.cs
- DesignerInterfaces.cs
- ResourcePool.cs
- Matrix3D.cs
- HttpInputStream.cs
- DesignTimeDataBinding.cs
- _ProxyRegBlob.cs
- AssemblyAttributesGoHere.cs
- TextServicesLoader.cs
- WebPartMenuStyle.cs
- WebBrowserNavigatedEventHandler.cs
- PixelShader.cs
- BamlResourceDeserializer.cs
- TextSpanModifier.cs
- CustomErrorCollection.cs
- CompoundFileDeflateTransform.cs
- ControlIdConverter.cs
- TdsParserHelperClasses.cs
- RSAPKCS1KeyExchangeFormatter.cs
- RtType.cs
- DockPatternIdentifiers.cs
- ObjectFullSpanRewriter.cs
- CodeGeneratorOptions.cs
- OleServicesContext.cs
- MatrixIndependentAnimationStorage.cs
- TextContainerChangedEventArgs.cs
- EmptyReadOnlyDictionaryInternal.cs
- DesignerLoader.cs
- XmlDataLoader.cs
- LicenseException.cs
- FrameworkObject.cs
- QuinticEase.cs
- HtmlMeta.cs
- reliableinputsessionchannel.cs
- InternalReceiveMessage.cs
- OrderedDictionary.cs
- GetPageNumberCompletedEventArgs.cs
- DropShadowBitmapEffect.cs
- ScrollEventArgs.cs
- ColumnMapTranslator.cs
- wmiutil.cs
- SessionPageStatePersister.cs
- CompilerResults.cs
- PropertyGridEditorPart.cs
- TableLayoutSettings.cs
- Error.cs
- ElementProxy.cs
- FixedTextPointer.cs
- ListViewUpdateEventArgs.cs
- WebPartHelpVerb.cs
- ValidationErrorCollection.cs
- ConnectionManagementSection.cs
- EventMap.cs
- ColorInterpolationModeValidation.cs
- PDBReader.cs
- MessageSmuggler.cs
- ResXResourceSet.cs
- SoapFormatterSinks.cs
- serverconfig.cs
- ReaderOutput.cs
- HtmlEncodedRawTextWriter.cs
- ItemType.cs
- BidPrivateBase.cs
- InputLangChangeEvent.cs
- OdbcInfoMessageEvent.cs
- ComAwareEventInfo.cs
- EditingCoordinator.cs
- ContentElement.cs
- HtmlEmptyTagControlBuilder.cs
- ValidationErrorEventArgs.cs
- BufferedStream2.cs
- DrawingGroup.cs
- UserControlFileEditor.cs
- ExpressionVisitor.cs
- AttributeUsageAttribute.cs
- UnknownWrapper.cs
- EntityKeyElement.cs
- CqlLexerHelpers.cs
- PointCollection.cs
- BitmapEffectDrawingContextState.cs
- StatementContext.cs
- DynamicILGenerator.cs