开发工具:
文件大小: 29mb
下载次数: 0
上传时间: 2019-07-20
详细说明:第三版
特別涵蓋 Windows Phone 專案
讓你的物件充分運用抽象化與繼承的強大威力
C#、XAML 與 .NET 編程實務的學習指南
探索 MVVM(Model-View-ViewModel)設計模式的絕妙奧義
『假如你想要以趣味橫生的方式深入學習 C#,這本書正是為你量身訂製的。』
— Andy Parker,C# 程式設計新手
『《深入淺出 C#》將引領各種背景的初學者一窺 C# 與 .NET Framework 的堂奧,並與之建立一段富有成效的長遠關係。』
— Chris Burrows,Microsoft C# Compiler 團隊的開發者
『《深入淺出 C#》讓我table of contents
objects: get oriente
Making Code Make Sense
Every program you write solves a problem
When you're building a program, it's always a good idea to start by thinking about what
problem your program's supposed to solve. Thats why objects are really useful. They
let you structure your code based on the problem it's solving, so that you can spend your
time thinking about the problem you need to work on rather than getting bogged down in
the mechanics of writing code. When you use objects right, you end up with code that 's
intuitive to write, and easy to read and change
How Mike thinks about his problems
How mike's car navigation system thinks about his problems
Mikes Navigator class has methods to set and modify routes
Use what you' ve learned to build a program that uses a class
Mike can use objects to solve his problem
You use a class to build an object
When you create a new object from a class, it's called an instance
of that class
94
Navigator
A better solution. brought to you by objects
Modify Route ToAvoidO)
Modify Route ToInclude(
newNavigator()
An instance uses fields to keep track of things
100
GetRouteO
Let's create some instances.
101
TotalDistanceO
gator dos What's on your programs mind
103
You can use class and method names to make your code intuitive
Give your classes a natural structure
Class diagrams help you organize your classes so they make sense 108
Build a class to work with some guy
112
Create a project for your guys
113
Build a form to interact with the guys
114
its methods, just like a blueprint
There's an easier way to initialize objects
117
defines the layout of the house
and you can use one class to
make any number of obiects
table of contents
pes and references
Its 10: 00. Do you know where your data is?
Data type, database, Lieutenant Commander Data.
it's all important stuff. Without data, your programs are useless. You
need information from your users, and you use that to look up or produce new
information to give back to them. In fact, almost everything you do in programming
involves working with data in one way or another. In this chapter, you'll learn the
ins and outs of Cts data types, see how to work with data in your program, and
even figure out a few dirty secrets about objects(pssst. . objects are data, too
The variable's type determines what kind of data it can store
126
A variable is like a data to-go cup
128
10 pounds of data in a 5 pound bag
Even when a number is the right size, you cant just assign it to
any variable
130
When you cast a value that's too big, C# will adjust it automatically 131
C# does some casting automaticall
132
When you call a method the arguments must be compatible
with the types of the parameters
133
Combining with an operator
138
Objects use variables, too
Refer to your objects with reference variables
140
References are like labels for your object
141
If there arent any more references, your object gets
D。 g fido
garbage-collected
142
Dog lucky new Dog()i
UCKY
Multiple references and their side effects
144
Two references means TwO ways to change an object's data
149
obje
special case: arrays
150
Wele
152
fido new Dog ()i
py Joe's Budget House o' Discount Sandwiches
Objects use references to talk to each other
154
Dog oos
Where no object has gone before
155
9 ob
Build a typing game
160
lucky null
Poof!!- FiDO
/、
obje
XIII
table of contents
G#了ab1
A Day at the races
Joe, Bob, and Al love going to the track, but they're
tired of losing all their money. They need you to build a
simulator for them so they can figure out winners before
they lay their money down. And, if you do a good job
they'lI cut you in on their profits
The spec: build a racetrack simulator
170
The Finished Product
178
A Day at the Races
table of contents
encapsulation
Keep your privates.a private
Ever wished for a little more privacy?
Sometimes your objects feel the same way. Just like you don 't want anybody you
dont trust reading your journal or paging through your bank statements, good objects
don t let other objects go poking around their fields. In this chapter, you're going to
learn about the power of encapsulation. You'l make your object's data private, and
add methods to protect how that data is accessed
Kathleen is an event planner
What does the estimator do?
181
Kathleen's Test drive
Each option should be calculated individually
188
It's easy to accidentally misuse your objects
190
Encapsulation means keeping some of the data in a class private 191
iget
Use encapsulation to control access to your class's methods
and field
192
But is the realName field REallY protected?
193
Private fields and methods can only be accessed from
inside the class
194
Encapsulation keeps your data pristine
202
Properties make encapsulation easier
203
76Aoerk
Build an application to test the Farmer class
204
Use automatic properties to finish the class
What if we want to change the feed multiplier?
206
Use a constructor to initialize private fields
Juice and soda
5
s7 discount on
(15 per p
total cost
+50 decorating
nUMber of
Health
feel
ple
Choice?
F00d(25
decorations?
Alcohol
NoVecorations
(20 per
750
person
person +13
I decorating fee
table of contents
inheritance
Your objects family tree
Sometimes you do want to be just like your parents
Ever run across an object that almost does exactly what you want your object to do?
Found yourself wishing that if you could just change a few things, that object would
be perfect? Well, that' s just one reason that inheritance is one of the most powerful
concepts and techniques in the C# language. Before you're through with this chapter,
you'll learn how to subclass an object to get its behavior, but keep the flexibility to
make changes to that behavior. You'll avoid duplicate code, model the real world
re closely, and end up with code that s easier to maintain
Kathleen does birthday parties. too
216
We need a birthday party class
217
Build the party Planner version 2.0
218
When your classes use inheritance, you only need to write
your code once
226
Kathleen needs to figure out the cost of her parties, no matter what
kind of parties they are
226
Build up your class model by starting general and getting
more specific
227
How would you design a zoo simulator?
228
Use inheritance to avoid duplicate code in subclasses
Think about how to group the animals
Create the class hierarchy
232
Every subclass extends its base class
233
A subclass can override methods to change or replace methods
it inherited
238
Any place where you can use a base class, you can use one of
its subclasses instead
239
A subclass can hide methods in the superclass
246
Use the override and virtual keywords to inherit behavior
248
Now you're ready to finish the job for Kathleen
25
Build a beehive management system
257
First you'l build the basic system
258
Use inheritance to extend the bee management system
263
table of contents
interfaces and abstract classes
Making classes keep their promises
Actions speak louder than words
Sometimes you need to group your objects together based on the things they can
do rather than the classes they inherit from That's where interfaces come in -they
let you work with any class that can do the job. But with great power comes great
responsibility, and any class that implements an interface must promise to fulfill all of
its obligations .. or the compiler will break their kneecaps, see?
x Inheritance
Let's get back to bee-sics
270
米
米
We can use inheritance to create classes for different types of bees 271
An interface tells a class that it must implement certain methods
米
Abstraction
and properties
Use the interface keyword to define an interface
273
Encapsulation
米
Classes that implement interfaces have to include all of the
interface's methods
275
米
You cant instantiate an interface, but you can reference an interface 278
米
Interface references work just like object references
279
amorphism
米
You can find out if a class implements a certain interface with "is" 280
Interfaces can inherit from other interfaces
281
Location
Name
casting works with both objects and interfaces
285
Exits
Downcasting lets you turn your appliance back into a coffee maker 286
Description(
Upcasting and downcasting work with interfaces, too
287
There's more than just public and private
Outside
Access modifiers change visibility
Decoration
Hot
Some classes should never be instantiated
295
An abstract class is like a cross between a class and an interface
296
An abstract method doesnt have a body
Polymorphism means that one object can take many different forms 307
Dining
Living room
Kitchen
Back Yard
XVIl
table of contents
enums and collections
Storing lots of data
When it rains, it pours
In the real world, you don 't get to handle your data in tiny little bits and pieces
No, your datas going to come at you in loads, piles, and bunches. You'll need
some pretty powerful tools to organize all of it, and that's where collections
come in. They let you store, sort, and manage all the data that your programs
need to pore through. That way, you can think about writing programs to work
with your data, and let the collections worry about keeping track of it for you
Strings don't always work for storing categories of data
328
Enums let you work with a set of valid values
Enums let you represent numbers with names
330
We could use an array to create a deck of cards
333
Lists are more flexible than arrays
336
Generics can store any type
340
Collection initializers work just like object initializers
344
Let's create a list of ducks
345
Lists are easy, but SORTING can be tricky
346
I Comparable helps your list sort its ducks
347
Use IComparer to tell your list how to sort
348
Create an instance of your comparer object
349
I Comparer can do complex comparisons
Overriding a To String method lets an object describe itself
353
Update your foreach loops to let your Ducks and cards
print themselves
354
You can upcast an entire list using IEnumerable
You can build your own overloaded methods
357
The Dictionary functionality rundown
364
Build a program that uses a dictionary
Poo!一
And yet more collection types
a queue is FiFO-First In, First Out
378
a stack is lifo-Last In. First Out
379
XVI
table of contents
G#了ab
The quest
Yourjob is to build an adventure game where a mighty
adventurer is on a quest to defeat level after level of
deadly enemies. You'll build a turn-based system, which
means the player makes one move and then the enemies
make one move. The player can move or attack, and then
each enemy gets a chance to move and attack. The game
keeps going until the player either defeats all the enemies
on all seven levels or dies
The spec: build an adventure game
386
The funs just beginning
406
The quest
Right
Don
Play
Bat
XIX
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.