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
- querybuilder.cs
- MobileDeviceCapabilitiesSectionHandler.cs
- XmlBinaryReader.cs
- LogSwitch.cs
- ControlPersister.cs
- PropertyRecord.cs
- AssertSection.cs
- XmlSchemaAll.cs
- StackSpiller.Bindings.cs
- MsmqProcessProtocolHandler.cs
- _UncName.cs
- Tokenizer.cs
- Deflater.cs
- WorkflowDesigner.cs
- QueryComponents.cs
- SQLChars.cs
- ManagedFilter.cs
- IteratorFilter.cs
- SmiConnection.cs
- QueryContinueDragEvent.cs
- ToolStripPanelRow.cs
- ToolStripStatusLabel.cs
- SecurityUtils.cs
- EntityException.cs
- Propagator.Evaluator.cs
- PageEventArgs.cs
- GlyphRun.cs
- MatcherBuilder.cs
- ContentType.cs
- AppDomainAttributes.cs
- DataKey.cs
- StylusShape.cs
- XmlChildNodes.cs
- MouseGestureConverter.cs
- CodeGen.cs
- SystemIPInterfaceProperties.cs
- RSAOAEPKeyExchangeDeformatter.cs
- ProvidePropertyAttribute.cs
- IdentityHolder.cs
- KeyPressEvent.cs
- XPathConvert.cs
- DigitalSignature.cs
- StrongNameMembershipCondition.cs
- X509IssuerSerialKeyIdentifierClause.cs
- XmlSchemaValidationException.cs
- InvariantComparer.cs
- StatusBarPanel.cs
- PersistencePipeline.cs
- ZipIOExtraFieldZip64Element.cs
- ServiceNameElement.cs
- RegexWorker.cs
- ImmComposition.cs
- XmlSchemaSearchPattern.cs
- DataGridCell.cs
- TextDocumentView.cs
- SafeEventLogWriteHandle.cs
- StructureChangedEventArgs.cs
- NodeFunctions.cs
- MaterialCollection.cs
- MetadataCacheItem.cs
- ConnectionInterfaceCollection.cs
- BitArray.cs
- XmlAtomicValue.cs
- AxHostDesigner.cs
- ResourceReader.cs
- XmlSchemaAll.cs
- TreePrinter.cs
- PrintEvent.cs
- EditCommandColumn.cs
- QilVisitor.cs
- MsmqIntegrationBindingElement.cs
- OperandQuery.cs
- ChtmlCommandAdapter.cs
- Effect.cs
- CommandEventArgs.cs
- KeyValuePair.cs
- XamlPoint3DCollectionSerializer.cs
- ListBoxChrome.cs
- DefaultAsyncDataDispatcher.cs
- XmlAutoDetectWriter.cs
- WebPartConnectionsDisconnectVerb.cs
- SoapAttributes.cs
- ApplicationException.cs
- SiteMap.cs
- BaseServiceProvider.cs
- ProfileService.cs
- ShaderEffect.cs
- SchemaObjectWriter.cs
- CustomErrorsSection.cs
- DocumentPageHost.cs
- TransformationRules.cs
- MD5Cng.cs
- PresentationAppDomainManager.cs
- TryCatch.cs
- WebProxyScriptElement.cs
- dataSvcMapFileLoader.cs
- SelectionItemProviderWrapper.cs
- DispatcherSynchronizationContext.cs
- HttpServerVarsCollection.cs
- TypeDescriptorContext.cs