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
- JsonServiceDocumentSerializer.cs
- ConfigurationManagerHelperFactory.cs
- HoistedLocals.cs
- TypeResolvingOptions.cs
- Byte.cs
- ClientViaElement.cs
- RelatedCurrencyManager.cs
- UrlAuthFailedErrorFormatter.cs
- LinkDescriptor.cs
- XmlDomTextWriter.cs
- CroppedBitmap.cs
- Attributes.cs
- Message.cs
- NamespaceCollection.cs
- CodeTypeReference.cs
- PathGradientBrush.cs
- ValueType.cs
- GAC.cs
- InlinedAggregationOperatorEnumerator.cs
- HyperLinkField.cs
- QuaternionAnimation.cs
- WindowsImpersonationContext.cs
- ArrayTypeMismatchException.cs
- ObjectListDesigner.cs
- DataTrigger.cs
- Globals.cs
- ToolStripLabel.cs
- DeviceSpecificChoiceCollection.cs
- CommandLineParser.cs
- ProtectedConfigurationSection.cs
- DetailsViewActionList.cs
- GestureRecognitionResult.cs
- WindowsSecurityTokenAuthenticator.cs
- ViewSimplifier.cs
- DaylightTime.cs
- WindowsFormsSynchronizationContext.cs
- EntityCommandDefinition.cs
- CryptoKeySecurity.cs
- SerializerProvider.cs
- MenuItem.cs
- XmlEntityReference.cs
- VerticalConnector.xaml.cs
- DesignerProperties.cs
- EncryptRequest.cs
- DataSvcMapFileSerializer.cs
- EntityCollection.cs
- Triangle.cs
- TemplateControlCodeDomTreeGenerator.cs
- NetNamedPipeSecurity.cs
- SelectionRange.cs
- XmlSchemaNotation.cs
- MobileFormsAuthentication.cs
- SHA384Managed.cs
- ColumnBinding.cs
- AdornerDecorator.cs
- CryptoApi.cs
- PeerCredentialElement.cs
- DataGridViewToolTip.cs
- Random.cs
- ExceptionUtility.cs
- RoleGroupCollectionEditor.cs
- UiaCoreProviderApi.cs
- SerializableAttribute.cs
- WindowsContainer.cs
- WindowProviderWrapper.cs
- nulltextcontainer.cs
- Evaluator.cs
- Model3D.cs
- FixedStringLookup.cs
- CacheRequest.cs
- WebPartEditorOkVerb.cs
- AvTraceDetails.cs
- ByteFacetDescriptionElement.cs
- HtmlAnchor.cs
- XslNumber.cs
- OperationAbortedException.cs
- IgnoreDeviceFilterElementCollection.cs
- SystemThemeKey.cs
- PropertyChangingEventArgs.cs
- IisTraceListener.cs
- PrinterResolution.cs
- HttpModuleCollection.cs
- StrongTypingException.cs
- TemplateBaseAction.cs
- ToolStripItemImageRenderEventArgs.cs
- ToolStripPanelRenderEventArgs.cs
- DataException.cs
- GatewayIPAddressInformationCollection.cs
- CounterSetInstance.cs
- _SSPIWrapper.cs
- filewebrequest.cs
- PeerNameRegistration.cs
- RuntimeHelpers.cs
- SQLDoubleStorage.cs
- RichTextBox.cs
- XamlSerializerUtil.cs
- StructuredType.cs
- BuildProviderCollection.cs
- StyleSheetRefUrlEditor.cs
- WebResourceUtil.cs