C# 0 The Complete Reference


double  by default), the  type of  e



Download 4,07 Mb.
Pdf ko'rish
bet105/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   101   102   103   104   105   106   107   108   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

double

 by default), the 

type of 

e

 is 


double

. Had 


e

 been declared like this:

var e = 2.7183F;

then


e

 would have the type 



float

, instead.

The following program demonstrates implicitly typed variables. It reworks the program 

shown in the preceding section so that all variables are implicitly typed.

//  Demonstrate implicitly typed variables.

using System;

class ImplicitlyTypedVar {

  static void Main() {

    // These are now implicitly typed variables. They

    // are of type double because their initializing

    // expressions are of type double.

    var s1 = 4.0;

    var s2 = 5.0;

    // Now, hypot is implicitly typed.  Its type is double

    // because the return type of Sqrt() is double.

    var hypot = Math.Sqrt( (s1 * s1) + (s2 * s2) );

    Console.Write("Hypotenuse of triangle with sides " +

                  s1 + " by " + s2 + " is ");

    Console.WriteLine("{0:#.###}.", hypot);

    // The following statement will not compile because

    // s1 is a double and cannot be assigned a decimal value.

www.freepdf-books.com




52

 

P a r t   I :  



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

//    s1 = 12.2M;  // Error!

  }

}

The output is the same as before.



It is important to emphasize that an implicitly typed variable is still a strongly typed 

variable. Notice this commented-out line in the program:

//    s1 = 12.2M;  // Error!

This assignment is invalid because 




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   101   102   103   104   105   106   107   108   ...   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