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

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Renderer.cs
- HtmlListAdapter.cs
- SessionStateUtil.cs
- CommandEventArgs.cs
- EventNotify.cs
- RemotingException.cs
- NotSupportedException.cs
- XPathDocumentNavigator.cs
- WorkflowTraceTransfer.cs
- Pen.cs
- ZoneIdentityPermission.cs
- PropertyBuilder.cs
- HierarchicalDataSourceControl.cs
- QueryReaderSettings.cs
- DynamicMetaObjectBinder.cs
- PathBox.cs
- TypeConverter.cs
- HttpCookiesSection.cs
- RangeValidator.cs
- SqlInfoMessageEvent.cs
- WaveHeader.cs
- TypedTableBase.cs
- ValidationHelpers.cs
- GraphicsPath.cs
- ProfileSettingsCollection.cs
- UIElement.cs
- MasterPageCodeDomTreeGenerator.cs
- InternalControlCollection.cs
- ExpressionParser.cs
- EnterpriseServicesHelper.cs
- Comparer.cs
- CommaDelimitedStringAttributeCollectionConverter.cs
- TypeTypeConverter.cs
- PropertyIDSet.cs
- MemberInfoSerializationHolder.cs
- WindowsStatusBar.cs
- Deflater.cs
- WinInetCache.cs
- WebPartEditorOkVerb.cs
- ClassImporter.cs
- CompareValidator.cs
- WebPartManagerInternals.cs
- CodePageEncoding.cs
- InputManager.cs
- RegionData.cs
- StringInfo.cs
- ListItemConverter.cs
- RequestSecurityTokenForRemoteTokenFactory.cs
- Rect.cs
- Icon.cs
- Typography.cs
- UrlMapping.cs
- Pkcs7Signer.cs
- MatrixIndependentAnimationStorage.cs
- WindowsScrollBarBits.cs
- SudsParser.cs
- OneOfTypeConst.cs
- TextAutomationPeer.cs
- ObjectItemCollectionAssemblyCacheEntry.cs
- DbgUtil.cs
- DataGridViewCellEventArgs.cs
- _BaseOverlappedAsyncResult.cs
- PriorityChain.cs
- MenuAdapter.cs
- Tokenizer.cs
- DomNameTable.cs
- Switch.cs
- DesignerLabelAdapter.cs
- ComplusTypeValidator.cs
- util.cs
- XmlNullResolver.cs
- InputMethodStateChangeEventArgs.cs
- TreeViewItem.cs
- SqlDelegatedTransaction.cs
- Empty.cs
- PageTextBox.cs
- Int64Converter.cs
- PointConverter.cs
- IRCollection.cs
- _HeaderInfo.cs
- RoleManagerEventArgs.cs
- ToolTip.cs
- HttpCacheVaryByContentEncodings.cs
- basecomparevalidator.cs
- FilterableAttribute.cs
- SetterBase.cs
- XmlDocument.cs
- BinaryUtilClasses.cs
- DataSourceSelectArguments.cs
- AmbiguousMatchException.cs
- ScriptReferenceEventArgs.cs
- shaperfactory.cs
- BindingExpressionUncommonField.cs
- DCSafeHandle.cs
- XPathException.cs
- UserControlCodeDomTreeGenerator.cs
- RenderData.cs
- LicFileLicenseProvider.cs
- BaseTreeIterator.cs
- FormsAuthenticationCredentials.cs