This print for content only-size & color not accurate 7" X 9-1/4" / casebound / malloy


// The compiler knows "s" is a System.String



Download 21,46 Mb.
Pdf ko'rish
bet826/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   822   823   824   825   826   827   828   829   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// The compiler knows "s" is a System.String.

var s = "This variable can only hold string data!";

s = "This is fine...";

// Can invoke any member of the underlying type.

string upper = s.ToUpper();



// Error! Can't assign numerical data to a a string!

s = 44;


}

C H A P T E R   1 3  



C #   2 0 0 8   L A N G U A G E   F E AT U R E S



419

8849CH13.qxd  10/2/07  12:42 PM  Page 419




Usefulness of Implicitly Typed Local Variables

Now that you have seen the syntax used to declare implicitly typed local variables, I am sure you are

wondering when to make use of this construct? First and foremost, using var to declare local vari-

ables simply for the sake of doing so really brings little to the table. Doing so can be confusing to

others reading your code, as it becomes harder to quickly determine the underlying data type (and

therefore more difficult to understand the overall functionality of the variable). Therefore, if you

know you need an int, declare an int!

However, as you will see beginning in Chapter 14, the LINQ technology set makes use of 



query

expressions that can yield dynamically created result sets based on the format of the query itself. In

these cases, implicit typing is extremely helpful, as we do not need to explicitly define the type that

a query may return, which in some cases would be literally impossible to do. Don’t get hung up on

the following LINQ example code; however, see if you can figure out the underlying data type of

subset:

static void QueryOverInts()

{

int[] numbers = { 10, 20, 30, 40, 1, 2, 3, 8 };



var subset = from i in numbers where i < 10 select i;

Console.Write("Values in subset: ");

foreach (var i in subset)

{

Console.Write("{0} ", i);



}

Console.WriteLine();




Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   822   823   824   825   826   827   828   829   ...   1830




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