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
- DESCryptoServiceProvider.cs
- WorkflowMessageEventArgs.cs
- BamlLocalizableResourceKey.cs
- PeerApplicationLaunchInfo.cs
- Expression.cs
- SafeThemeHandle.cs
- ColorInterpolationModeValidation.cs
- WeakReferenceList.cs
- ValidationRuleCollection.cs
- DynamicVirtualDiscoSearcher.cs
- WindowsTokenRoleProvider.cs
- MetadataCache.cs
- UnsafeNativeMethods.cs
- DecodeHelper.cs
- TypeReference.cs
- XmlSecureResolver.cs
- Timer.cs
- BufferedStream.cs
- ReadWriteSpinLock.cs
- AtomMaterializerLog.cs
- SystemIPGlobalProperties.cs
- IconBitmapDecoder.cs
- CmsUtils.cs
- SqlSupersetValidator.cs
- TemplateControlParser.cs
- DataGridViewRowsRemovedEventArgs.cs
- DocumentSequenceHighlightLayer.cs
- TextEditorParagraphs.cs
- FloaterParagraph.cs
- HttpDictionary.cs
- OletxResourceManager.cs
- MasterPageBuildProvider.cs
- BitmapDecoder.cs
- Cursors.cs
- PlainXmlWriter.cs
- ParameterInfo.cs
- DataGridViewToolTip.cs
- ClusterSafeNativeMethods.cs
- WebUtility.cs
- GlyphRunDrawing.cs
- SimpleWorkerRequest.cs
- XDeferredAxisSource.cs
- Action.cs
- BufferBuilder.cs
- XmlCharCheckingWriter.cs
- AttachedAnnotationChangedEventArgs.cs
- RequestQueryProcessor.cs
- HtmlControl.cs
- OracleNumber.cs
- RequestReplyCorrelator.cs
- TextEditorSpelling.cs
- CqlErrorHelper.cs
- ResXResourceSet.cs
- HttpCachePolicy.cs
- safePerfProviderHandle.cs
- XmlUrlResolver.cs
- SingleAnimationBase.cs
- DataViewSetting.cs
- ToolZoneDesigner.cs
- UInt64Converter.cs
- MenuItemCollectionEditorDialog.cs
- ViewCellSlot.cs
- XmlSchemaSimpleType.cs
- ErrorStyle.cs
- unitconverter.cs
- DecryptRequest.cs
- EmptyEnumerator.cs
- AmbientLight.cs
- XamlGridLengthSerializer.cs
- EpmContentDeSerializerBase.cs
- Operator.cs
- DataSysAttribute.cs
- DataSourceControlBuilder.cs
- MarkedHighlightComponent.cs
- MailMessage.cs
- BitmapEffectDrawing.cs
- ProfileEventArgs.cs
- ComponentDispatcher.cs
- TabControlEvent.cs
- UnSafeCharBuffer.cs
- HttpStreamFormatter.cs
- MethodBuilderInstantiation.cs
- SaveWorkflowAsyncResult.cs
- PenContexts.cs
- PathFigure.cs
- HtmlInputFile.cs
- ScrollChrome.cs
- TargetParameterCountException.cs
- Identifier.cs
- EncoderReplacementFallback.cs
- mda.cs
- NamespaceQuery.cs
- EUCJPEncoding.cs
- AppSettings.cs
- CqlQuery.cs
- WindowsGraphics.cs
- DataList.cs
- SwitchLevelAttribute.cs
- UriParserTemplates.cs
- Label.cs