C# 0 The Complete Reference


double  parameters. Notice that the first two versions of  OvlDemo( )



Download 4,07 Mb.
Pdf ko'rish
bet261/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   257   258   259   260   261   262   263   264   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

double

 parameters. Notice that the first two versions of 



OvlDemo( )

 return 


void

 and the second two return a value. This is perfectly valid, but as explained, overloading 

is not affected one way or the other by the return type of a method. Thus, attempting to use 

these two versions of 



OvlDemo( )

 will cause an error:

// One OvlDemo(int) is OK.

public void OvlDemo(int a) {

  Console.WriteLine("One parameter: " + a);

}

/* Error! Two OvlDemo(int)s are not OK even though



    return types differ. */

public int OvlDemo(int a) {

  Console.WriteLine("One parameter: " + a);

  return a * a;

}

As the comments suggest, the difference in their return types is an insufficient difference for 



the purposes of overloading.

As you will recall from Chapter 3, C# provides certain implicit (i.e., automatic) type 

conversions. These conversions also apply to parameters of overloaded methods. For 

example, consider the following:

// Implicit type conversions can affect overloaded method resolution.

using System;

class Overload2 {

  public void MyMeth(int x) {

    Console.WriteLine("Inside MyMeth(int): " + x);

  }


  public void MyMeth(double x) {

    Console.WriteLine("Inside MyMeth(double): " + x);

  }

}

class TypeConv {



  static void Main() {

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   257   258   259   260   261   262   263   264   ...   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