C# 0 The Complete Reference


Swap( )  refer. Before calling  Swap( )



Download 4,07 Mb.
Pdf ko'rish
bet253/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   249   250   251   252   253   254   255   256   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

Swap( )

 refer. Before calling 



Swap( )

,

x

 refers to an object that contains the values 1 and 2, 

and


y

 refers to an object that contains the values 3 and 4. After the call to 



Swap( )

,

x

 refers to 

the object that contains the values 3 and 4, and 



y

 refers to the object that contains the values 

1 and 2. If 

ref

 parameters had not been used, then the exchange inside 



Swap( )

 would have 

had no effect outside 

Swap( )

. You might want to prove this by removing 



ref

 from 


Swap( )

.

Use a Variable Number of Arguments

When you create a method, you usually know in advance the number of arguments that 

you will be passing to it, but this is not always the case. Sometimes you will want to create 

a method that can be passed an arbitrary number of arguments. For example, consider a 

method that finds the smallest of a set of values. Such a method might be passed as few 

as two values, or three, or four, and so on. In all cases, you want that method to return the 

smallest value. Such a method cannot be created using normal parameters. Instead, you 

must use a special type of parameter that stands for an arbitrary number of parameters. 

This is done by creating a 



params

 parameter.

The

params

 modifier is used to declare an array parameter that will be able to receive 

zero or more arguments. The number of elements in the array will be equal to the number 

of arguments passed to the method. Your program then accesses the array to obtain the 

arguments.

Here is an example that uses 



params

 to create a method called 



MinVal( )

, which returns 

the minimum value from a set of values:

// Demonstrate params.

using System;

class Min {

  public int MinVal(params int[] nums) {

    int m;

    if(nums.Length == 0) {

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   249   250   251   252   253   254   255   256   ...   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