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
- Journaling.cs
- LinqDataSourceValidationException.cs
- SelectQueryOperator.cs
- TextContainerHelper.cs
- StaticExtension.cs
- DetailsViewPagerRow.cs
- DbParameterCollection.cs
- DirectoryObjectSecurity.cs
- DirtyTextRange.cs
- ProtocolsConfigurationHandler.cs
- XmlSerializerObjectSerializer.cs
- DetailsViewModeEventArgs.cs
- DecodeHelper.cs
- QilSortKey.cs
- View.cs
- FormsAuthenticationTicket.cs
- CategoriesDocumentFormatter.cs
- Ray3DHitTestResult.cs
- TriggerCollection.cs
- ValidationSummary.cs
- SettingsAttributes.cs
- XmlQueryRuntime.cs
- RepeatEnumerable.cs
- AppDomain.cs
- CodeChecksumPragma.cs
- NodeFunctions.cs
- sapiproxy.cs
- EncryptedReference.cs
- DownloadProgressEventArgs.cs
- ToolConsole.cs
- ObjRef.cs
- PixelShader.cs
- PlainXmlDeserializer.cs
- ExpressionBindings.cs
- MessagePartDescriptionCollection.cs
- LoopExpression.cs
- NotificationContext.cs
- ManualResetEvent.cs
- MailBnfHelper.cs
- PropertyPanel.cs
- JsonFaultDetail.cs
- localization.cs
- Annotation.cs
- DataGridViewAutoSizeModeEventArgs.cs
- HtmlInputRadioButton.cs
- StylusPlugin.cs
- FlowLayout.cs
- BrowserCapabilitiesFactoryBase.cs
- ErrorTableItemStyle.cs
- Trace.cs
- versioninfo.cs
- WebBrowserNavigatingEventHandler.cs
- DocumentSchemaValidator.cs
- PairComparer.cs
- EventLogEntry.cs
- WindowsGrip.cs
- XmlSchemaDocumentation.cs
- MergablePropertyAttribute.cs
- ColorComboBox.cs
- Inline.cs
- DataControlFieldCollection.cs
- EntityDataSourceWrapperCollection.cs
- DashStyles.cs
- TargetFrameworkUtil.cs
- ListViewCommandEventArgs.cs
- HttpPostLocalhostServerProtocol.cs
- RangeValidator.cs
- Bold.cs
- DefaultPropertiesToSend.cs
- ToolboxDataAttribute.cs
- ChangeTracker.cs
- ArgumentException.cs
- _KerberosClient.cs
- QilVisitor.cs
- Pen.cs
- TCPClient.cs
- TextAdaptor.cs
- OdbcConnectionStringbuilder.cs
- EventDescriptor.cs
- WebUtility.cs
- WindowsToolbarItemAsMenuItem.cs
- DataGridViewColumnStateChangedEventArgs.cs
- XmlSchemaSimpleContent.cs
- OleDbConnectionInternal.cs
- Unit.cs
- UndirectedGraph.cs
- SharedConnectionInfo.cs
- WebServiceHostFactory.cs
- CoTaskMemSafeHandle.cs
- Identifier.cs
- ETagAttribute.cs
- SrgsDocumentParser.cs
- PipelineModuleStepContainer.cs
- EncoderBestFitFallback.cs
- XmlHelper.cs
- BufferedStream.cs
- RegexBoyerMoore.cs
- DefaultObjectSerializer.cs
- TextBlockAutomationPeer.cs
- AuthStoreRoleProvider.cs