Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- ChannelAcceptor.cs
- CodeRegionDirective.cs
- CodeParameterDeclarationExpressionCollection.cs
- StrokeCollectionConverter.cs
- _HelperAsyncResults.cs
- ConsoleEntryPoint.cs
- TranslateTransform3D.cs
- XmlnsDictionary.cs
- NotifyInputEventArgs.cs
- SafeFileMapViewHandle.cs
- VisualTarget.cs
- CustomAttributeBuilder.cs
- ModelFunctionTypeElement.cs
- DataGridViewTopRowAccessibleObject.cs
- GridViewRowEventArgs.cs
- Component.cs
- WorkflowInstanceExtensionManager.cs
- SoapElementAttribute.cs
- DecimalStorage.cs
- Sentence.cs
- DbConnectionClosed.cs
- DefaultPropertiesToSend.cs
- CodeValidator.cs
- RewritingPass.cs
- BufferModesCollection.cs
- EditBehavior.cs
- HtmlImageAdapter.cs
- Transform.cs
- BitmapScalingModeValidation.cs
- DataServiceRequestException.cs
- VersionedStreamOwner.cs
- RenamedEventArgs.cs
- LicenseManager.cs
- HttpHandlerActionCollection.cs
- ConnectionInterfaceCollection.cs
- AttributeExtensions.cs
- DateTimeSerializationSection.cs
- DrawingAttributesDefaultValueFactory.cs
- SiblingIterators.cs
- FileSystemInfo.cs
- BackgroundWorker.cs
- Compiler.cs
- SystemParameters.cs
- Variable.cs
- DataGridState.cs
- KeyValueConfigurationElement.cs
- WebDisplayNameAttribute.cs
- WebResponse.cs
- MachineKeyConverter.cs
- BasePattern.cs
- MethodToken.cs
- RegexStringValidator.cs
- FixedSOMPageElement.cs
- GACMembershipCondition.cs
- XmlQueryOutput.cs
- CookieHandler.cs
- AssemblyAssociatedContentFileAttribute.cs
- XmlSchemaCompilationSettings.cs
- CodeStatement.cs
- ContextActivityUtils.cs
- Enlistment.cs
- DesignerObject.cs
- WebPartChrome.cs
- ComPlusSynchronizationContext.cs
- Rect3DValueSerializer.cs
- QueryResponse.cs
- GifBitmapDecoder.cs
- HostingPreferredMapPath.cs
- ProxyGenerationError.cs
- CryptoApi.cs
- ClosableStream.cs
- MatrixTransform3D.cs
- TreeNodeCollection.cs
- BrowserCapabilitiesCompiler.cs
- TaskDesigner.cs
- TypeDelegator.cs
- Currency.cs
- MergeLocalizationDirectives.cs
- ParserHooks.cs
- CheckBoxStandardAdapter.cs
- ExtensionQuery.cs
- UserControlCodeDomTreeGenerator.cs
- DbConnectionPoolIdentity.cs
- SecurityElement.cs
- TypeUtil.cs
- DSACryptoServiceProvider.cs
- SqlRecordBuffer.cs
- BinaryUtilClasses.cs
- MethodBuilderInstantiation.cs
- BuildProvidersCompiler.cs
- ClientData.cs
- WebHttpBindingElement.cs
- BindingContext.cs
- DataViewSetting.cs
- ImageList.cs
- CompareValidator.cs
- TableNameAttribute.cs
- DirectionalLight.cs
- SettingsAttributes.cs
- MetadataUtilsSmi.cs