C# 0 The Complete Reference


Pop( ) . You can  use Peek( )



Download 4,07 Mb.
Pdf ko'rish
bet955/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   951   952   953   954   955   956   957   958   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

Pop( )

. You can 

use

Peek( )

 to return, but not remove, the top object. An 



InvalidOperationException

 is 


thrown if you call 

Pop( )

 or 


Peek( )

 when the invoking stack is empty.

Method

Description



public vir tual void Clear( )

Sets 


Count

 to zero, which effectively clears 

the stack.

public vir tual bool Contains(object 



v

)

Returns true if 



v

 is on the invoking stack. If 



v

is not found, false is returned.

public vir tual object Peek( )

Returns the element on the top of the stack, 

but does not remove it.

public vir tual object Pop( )

Returns the element on the top of the stack, 

removing it in the process.

public vir tual void Push(object 

v

)

Pushes 



v

 onto the stack. 

public static Stack Synchronized(Stack 

stk

)

Returns a synchronized version of the 



Stack

passed in 



stk.

public vir tual object[ ] ToArray( )

Returns an array that contains copies of the 

elements of the invoking stack.

T

ABLE


 24-7 

The Methods Defi ned by 

Stack

www.freepdf-books.com




768

 

P a r t   I I :  



E x p l o r i n g   t h e   C #   L i b r a r y

Here is an example that creates a stack, pushes several integers onto it, and then pops 

them off again:

// Demonstrate the Stack class.

using System;

using System.Collections;

class StackDemo {

  static void ShowPush(Stack st, int a) {

    st.Push(a);

    Console.WriteLine("Push(" + a + ")");

    Console.Write("stack: ");

    foreach(int i in st)

      Console.Write(i + " ");

    Console.WriteLine();

  }

  static void ShowPop(Stack st) {



    Console.Write("Pop -> ");

    int a = (int) st.Pop();

    Console.WriteLine(a);

    Console.Write("stack: ");

    foreach(int i in st)

      Console.Write(i + " ");

    Console.WriteLine();

  }


  static void Main() {

    Stack st = new Stack();

    foreach(int i in st)

      Console.Write(i + " ");

    Console.WriteLine();

    ShowPush(st, 22);

    ShowPush(st, 65);

    ShowPush(st, 91);

    ShowPop(st);

    ShowPop(st);

    ShowPop(st);

    try {

      ShowPop(st);

    } catch (InvalidOperationException) {

      Console.WriteLine("Stack empty.");

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   951   952   953   954   955   956   957   958   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish