14.02.2017 Views

. Стиллмен, Дж. Грин - Изучаем C#, 2-е издание

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

-Jo3bM H в руку карандаш<br />

инкапсуляция<br />

П<strong>е</strong>р<strong>е</strong>д вами класс с закрытыми полями. Обв<strong>е</strong>дит<strong>е</strong> оп<strong>е</strong>раторы,<br />

которы<strong>е</strong> н<strong>е</strong> будут компилироваться, <strong>е</strong>сли их запустить извн<strong>е</strong><br />

класса, используя экз<strong>е</strong>мпляр объ<strong>е</strong>кта mySuperChef.<br />

class SuperChef<br />

{<br />

public string cookieRecipe;<br />

private string secretlngredient;<br />

private const int loyalCustomerOrderAmount = 60;<br />

public int Temperature;<br />

private string ingredientSupplier;<br />

public string GetRecipe (int orderAmount)<br />

{<br />

if (orderAmount >= loyalCustomerOrderAmount)<br />

else<br />

return cookieRecipe;<br />

1. string ovenTemp = mySuperChef.Temperature;<br />

2. string supplier = mySuperChef.ingredientSupplier;<br />

3. int loyalCustomerOrderAmount = 94;<br />

4. mySuperChef.secretlngredient = "кардамон";<br />

5. mySuperChef.cookieRecipe = "3 яйца, 2 1/2 чашки муки, 1 ст. л. соли,<br />

1 ст. л. ванили и 1.5 чашки сахара см<strong>е</strong>шать. Вып<strong>е</strong>кать 10 минут при<br />

т<strong>е</strong>мп<strong>е</strong>ратур<strong>е</strong> 190 °С. Приятного апп<strong>е</strong>тита!";<br />

6. string recipe = mySuperChef.GetRecipe(56);<br />

7. Како<strong>е</strong> знач<strong>е</strong>ни<strong>е</strong> буд<strong>е</strong>т им<strong>е</strong>ть п<strong>е</strong>р<strong>е</strong>м<strong>е</strong>нная recipe посл<strong>е</strong> запуска вс<strong>е</strong>х этих строк кода?<br />

дальш<strong>е</strong> > 211

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!