Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Collections / Stack.cs / 1305376 / Stack.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================================== ** ** Class: Stack ** **[....] ** ** Purpose: An array implementation of a stack. ** ** =============================================================================*/ namespace System.Collections { using System; using System.Security.Permissions; using System.Diagnostics; using System.Diagnostics.Contracts; // A simple stack of objects. Internally it is implemented as an array, // so Push can be O(n). Pop is O(1). [DebuggerTypeProxy(typeof(System.Collections.Stack.StackDebugView))] [DebuggerDisplay("Count = {Count}")] [System.Runtime.InteropServices.ComVisible(true)] [Serializable] public class Stack : ICollection, ICloneable { private Object[] _array; // Storage for stack elements [ContractPublicPropertyName("Count")] private int _size; // Number of items in the stack. private int _version; // Used to keep enumerator in [....] w/ collection. [NonSerialized] private Object _syncRoot; private const int _defaultCapacity = 10; public Stack() { _array = new Object[_defaultCapacity]; _size = 0; _version = 0; } // Create a stack with a specific initial capacity. The initial capacity // must be a non-negative number. public Stack(int initialCapacity) { if (initialCapacity < 0) throw new ArgumentOutOfRangeException("initialCapacity", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); if (initialCapacity < _defaultCapacity) initialCapacity = _defaultCapacity; // Simplify doubling logic in Push. _array = new Object[initialCapacity]; _size = 0; _version = 0; } // Fills a Stack with the contents of a particular collection. The items are // pushed onto the stack in the same order they are read by the enumerator. // public Stack(ICollection col) : this((col==null ? 32 : col.Count)) { if (col==null) throw new ArgumentNullException("col"); Contract.EndContractBlock(); IEnumerator en = col.GetEnumerator(); while(en.MoveNext()) Push(en.Current); } public virtual int Count { get { Contract.Ensures(Contract.Result() >= 0); return _size; } } public virtual bool IsSynchronized { get { return false; } } public virtual Object SyncRoot { get { if( _syncRoot == null) { System.Threading.Interlocked.CompareExchange
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AnnotationHighlightLayer.cs
- CommandEventArgs.cs
- OpCodes.cs
- DataGridAutoGeneratingColumnEventArgs.cs
- PriorityChain.cs
- CodeIndexerExpression.cs
- BuildResultCache.cs
- FileCodeGroup.cs
- ContainerParagraph.cs
- CollectionViewGroupInternal.cs
- MobileControlsSectionHandler.cs
- CommandHelpers.cs
- XmlQueryCardinality.cs
- OracleCommandBuilder.cs
- HttpCookie.cs
- ConfigXmlText.cs
- FreezableCollection.cs
- DataGridPageChangedEventArgs.cs
- MaterializeFromAtom.cs
- CommonXSendMessage.cs
- XDRSchema.cs
- ProviderBase.cs
- HtmlTitle.cs
- Delegate.cs
- ModifierKeysValueSerializer.cs
- Container.cs
- BaseCAMarshaler.cs
- FixedSOMPageConstructor.cs
- ChannelManager.cs
- XmlElementAttributes.cs
- ToolboxBitmapAttribute.cs
- SqlUtils.cs
- ResourceDescriptionAttribute.cs
- XmlSortKeyAccumulator.cs
- ImportDesigner.xaml.cs
- HtmlWindowCollection.cs
- MethodToken.cs
- SmtpTransport.cs
- SequentialActivityDesigner.cs
- HttpRuntimeSection.cs
- IItemContainerGenerator.cs
- Listen.cs
- HitTestFilterBehavior.cs
- BoundPropertyEntry.cs
- XmlSchemaSimpleTypeRestriction.cs
- FontUnit.cs
- ConfigXmlAttribute.cs
- FlowDocumentReader.cs
- UseLicense.cs
- SerializableAuthorizationContext.cs
- FormViewRow.cs
- CompensationParticipant.cs
- HostAdapter.cs
- SymbolMethod.cs
- CheckBoxList.cs
- FollowerQueueCreator.cs
- WebGetAttribute.cs
- StaticContext.cs
- MimeBasePart.cs
- CodeObjectCreateExpression.cs
- XmlParserContext.cs
- ContactManager.cs
- FileIOPermission.cs
- BasicBrowserDialog.cs
- HiddenFieldDesigner.cs
- XsdBuilder.cs
- MediaCommands.cs
- ArrangedElementCollection.cs
- JournalEntry.cs
- AddressHeaderCollectionElement.cs
- UseLicense.cs
- SapiAttributeParser.cs
- WizardForm.cs
- QueryBranchOp.cs
- SessionSwitchEventArgs.cs
- FormatConvertedBitmap.cs
- DataGridViewAccessibleObject.cs
- WebResourceAttribute.cs
- UIElement.cs
- CompilerTypeWithParams.cs
- SoapAttributeAttribute.cs
- SynchronizationScope.cs
- DataGridViewCellPaintingEventArgs.cs
- DataGridView.cs
- SchemaCollectionPreprocessor.cs
- DictionaryGlobals.cs
- PermissionSet.cs
- GatewayDefinition.cs
- BuilderInfo.cs
- ADMembershipProvider.cs
- DataGridViewColumnHeaderCell.cs
- BindingsCollection.cs
- HttpListener.cs
- DependencyObjectPropertyDescriptor.cs
- GregorianCalendarHelper.cs
- InkPresenterAutomationPeer.cs
- HtmlAnchor.cs
- ToolStripPanelCell.cs
- XmlQueryOutput.cs
- TypeElement.cs