C# 0 The Complete Reference


a , was indeed modified by  Sqr( )



Download 4,07 Mb.
Pdf ko'rish
bet247/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   243   244   245   246   247   248   249   250   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

a

, was indeed modified by 



Sqr( )

:

a before call: 10



a after call: 100

Using


ref

, it is now possible to write a method that exchanges the values of its two 

value-type arguments. For example, here is a program that contains a method called 

Swap( )

 that exchanges the values of the two integer arguments with which it is called:

// Swap two values.

using System;

class ValueSwap {

  // This method now changes its arguments.

  public void Swap(ref int a, ref int b) {

    int t;

www.freepdf-books.com



178

 

P a r t   I :  



T h e   C #   L a n g u a g e

    t = a;

    a = b;

    b = t;

  }

}

class ValueSwapDemo {



  static void Main() {

    ValueSwap ob = new ValueSwap();

    int x = 10, y = 20;

    Console.WriteLine("x and y before call: " + x + " " + y);

    ob.Swap(ref x, ref y);

    Console.WriteLine("x and y after call: " + x + " " + y);

  }

}

The output from this program is shown here:



x and y before call: 10 20

x and y after call: 20 10

Here is one important point to understand about 


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   243   244   245   246   247   248   249   250   ...   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