Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Buy Now $29.99
Standard view
Full view
of .
Look up keyword or section
Like this
1Activity

Table Of Contents

Introduction
What’s New in C# 3.0
About This Book
What You Need to Use the Book
How to Use This Book
How This Book Is Organized
Part I: Getting Started with C#
Part II: Basic C# Programming
Part III: Using Objects
Part IV: Object-Oriented Programming
Part V: Now Showing in C# 3.0
Part VI: The Part of Tens
About the Web site
Icons Used in This Book
Conventions Used in This Book
Where’s the Code? And the Bonus Goodies?
Where to Go from Here
Chapter 1
Getting a Handle on Computer Languages, C#, and .NET
What’s a program?
What’s C#?
What’s .NET?
What is Visual Studio 2008? What about Visual C#?
Creating Your First Console Application
Creating the source program
Taking it out for a test drive
Making Your Console App Do Something
Reviewing Your Console Application
The program framework
Comments
The meat of the program
Introducing the Toolbox Trick
Saving code in the Toolbox
Reusing code from the Toolbox
Living with Variability — Declaring Value-Type Variables
Declaring a Variable
Comparing decimals, integers, and floating-point types
Examining the bool Type — Is It Logical?
Checking Out Character Types
The char variable type
Special chars
The string type
What’s a Value-Type?
Comparing string and char
Is This a Leap Year? — DateTime
Declaring Numeric Constants
Changing Types — The Cast
New Feature: Letting the C# Compiler Infer Data Types
Performing Arithmetic
Simple operators
Operating orders
The assignment operator
The increment operator
Performing Logical Comparisons — Is That Logical?
Compounding the confusion with compound logical operations
Matching Expression Types at TrackDownAMate.com
Calculating the type of an operation
Assigning types
Branching Out with if and switch
Introducing the if statement
Examining the else statement
Avoiding even the else
Nesting if statements
Running the switchboard
Here We Go Loop the Loop
Looping for a while
Doing the do . . . while loop
Breaking up is easy to do
Looping until you get it right
Focusing on scope rules
Looping a Specified Number of Times with for
An example
Why do you need another loop?
Nesting Loops
Don’t goto Pieces
The C# Array
The argument for the array
The fixed-value array
The variable-length array
The Length property
How do I initialize my array?
A Loop Made foreach Array
Sorting Through Arrays of Data
New Feature — Using var for Arrays
Loosening Up with C# Collections
Understanding Collection Syntax
C#’s collection classes
Figuring out <T>
Going generic
Using Lists
Using Dictionaries
New Feature — Array and Collection Initializers
Initializing arrays
Initializing collections
New Feature — Using Sets
On Not Using Old-Fashioned Collections
The Union Is Indivisible, and So Are Strings
Performing Common Operations on a String
Comparing Strings
Equality for all strings: The Compare() method
Would you like your compares with or without case?
What If I Want to Switch Case?
Converting a string to upper- or lowercase
Looping Through a String
Searching Strings
Can I find it?
Is my string empty?
Getting Input from the Command Line
Trimming excess white space
Parsing numeric input
Handling a series of numbers
Joining an array of strings into one string
Controlling Output Manually
Using the Trim() and Pad() methods
Using the Concatenate() method
Let’s Split() that concatenate program
Formatting Your Strings Precisely
StringBuilder: Manipulating Strings More Efficiently
What’s an Object? What’s a Class?
Defining a class
What’s the object?
Accessing the Members of an Object
An Example Object-Based Program
Discriminating Between Objects
Can You Give Me References?
Generating Static in Class Members
Defining const and readonly Data Members
Defining and Using a Method
An Example Method for Your Files
Having Arguments with Methods
Passing an argument to a method
Passing multiple arguments to methods
Matching argument definitions with usage
Implementing default arguments
Passing Value-Type and Reference-Type Arguments
Passing value-type arguments by value
Passing value-type arguments by reference
Passing reference-type arguments
Returning Values after Christmas
Returning a value via return postage
Returning a value using pass-by-reference
When do I return and when do I out?
Defining a method with no value
ᮣPassing an object to a method
Passing an Object to a Method
Defining Methods
Defining a static method
Defining an instance method
Expanding a method’s full name
Accessing the Current Object
What is the this keyword?
When is this explicit?
What happens when I don’t have this?
New Feature: Extension Methods
Object-Oriented Concept #1 — Abstraction
Preparing procedural nachos
Preparing object-oriented nachos
Object-Oriented Concept #2 — Classification
Why Classify?
Object-Oriented Concept #3 — Usable Interfaces
Object-Oriented Concept #4 — Access Control
How Does C# Support Object-Oriented Concepts?
Restricting Access to Class Members
A public example of public BankAccount
Jumping ahead — other levels of security
Why Worry about Access Control?
Accessor methods
Access control to the rescue — an example
So what?
Defining Class Properties
Static properties
Properties with side effects
New Feature: Let the compiler write properties for you
Accessors with access levels
Getting Your Objects Off to a Good Start — Constructors
The C#-Provided Constructor
Replacing the Default Constructor
Constructing something
Executing the constructor from the debugger
Initializing an object directly with an initializer
Seeing that construction stuff with initializers
New Feature — Initializing an object without a constructor
Avoiding Duplication among Constructors
Being Object-Stingy
Inheriting a Class
Why Do You Need Inheritance?
A More Involved Example — Inheriting from a BankAccount Class
IS_A versus HAS_A — I’m So Confused
The IS_A relationship
Gaining access to BankAccount through containment
The HAS_A relationship
When to IS_A and When to HAS_A?
Other Features That Support Inheritance
Getting specific with base
The Updated BankAccount Class
Overloading an Inherited Method
It’s a simple case of method overloading
Different class, different method
Peek-a-boo — hiding a base class method
Calling back to base
Polymorphism
What’s wrong with using the declared type every time?
Using “is” to access a hidden method polymorphically
Declaring a method virtual and overriding it
The Class Business Card: ToString()
C# During Its Abstract Period
Class factoring
I’m left with nothing but a concept — the abstract class
How do you use an abstract class?
Creating an abstract object — not!
Sealing a Class
What Is CAN_BE_USED_AS?
What Is an Interface?
How to implement an interface
How to name your interface
So why does C# include interfaces?
Mixing inheritance and interface implementation
And here’s the payoff
Using an Interface
ߜAs method return types
As a method return type
As the base type of an array or collection
As a more general type of object reference
Using C#’s Predefined Interface Types
Can I See a Program That CAN_ BE_USED_AS an Example?
Creating your own interface at home in your spare time
Implementing the incomparable IComparable<T> interface
Putting it all together
Getting back to the Main() event
Unifying Class Hierarchies
Hiding Behind an Interface
Inheriting an Interface
Using Interfaces to Manage Change in Object-Oriented Programs
Flexible dependencies through interfaces
Doing HAS_A with interfaces
The Strategy Design Pattern
What makes this pattern so useful?
E.T. Phone Home — The Callback Problem
What’s a Delegate?
Pass Me the Code, Please — Examples
I delegated the example to Igor
First, a very simple example
The Observer design pattern
What’s an event? Publish and Subscribe
How a publisher advertises its events
How do subscribers subscribe to an event?
How do I publish an event?
How do I pass extra information to an event handler?
A recommended way to raise your events
How do observers “handle” an event?
Collections and the Do-to-Each Problem
New Feature: Using Lambda Expressions
The C# way to do-to-each
Grist for the mill: Data for the examples
Looking for answers: Some Find() examples
Taking action: Some ForEach() examples
A lambda based on a custom delegate
Summary of the examples
Details of lambda syntax
Using Lambda Expressions for Any Delegate
Reviewing the C# 3.0 Features
What’s a Query, and Why Should I Care?
Why is “language-integrated” query important?
The general form of a C# query
LINQ from low Earth orbit
Querying in C# 3.0
The three most important query operators
What is deferred query execution?
Evaluating a query immediately
What Can I Do with a Query?
Filtering Out the Espresso Grounds
Example 1: Which customers live in Colorado?
Selecting and Grouping What You Want
Using anonymous types
Example 4: Transforming numbers into their names
Example 5: Grouping names by their first character
Is There Any Method to Querying?
About train cars: A detour for newbies
End of detour — All aboard!
Generic methods
What’s inside Where()?
Counting, Summing, Averaging, and Stuff Like That
Example 14: Counting product types in our inventory
Example 15: Adding up the numbers array
Example 16: Summing the cost of order O
Example 17: Computing nine factorial (9!)
Treating an Object Like a Collection
Cannot implicitly convert type ‘x’ into ‘y’
Use of unassigned local variable ‘n’
‘methodName’ : not all code paths return a value
} expected
Index
P. 1
C# 2008 For Dummies

C# 2008 For Dummies

Ratings:

2.75

(2)
|Views: 60|Likes:
Published by Wiley
Whether you’re a total novice or a programmer shifting to C#,the newest version of this programming language is full of coolfeatures you’ll want to use. With its Visual Studiocompatibility, C# is the perfect language for building WindowsVista applications. And the 2008 version works with LINQ, a querylanguage with syntax similar to SQL but which simplifies databasecode and can also write queries on XML files.

For the best basic C# how-to, it’s hard to beat C# 2008For Dummies. This plain-English guide to programming with C#can have you creating your first console application before youfinish Part I. In fact, the basic template you create at that pointwill be the foundation of many other apps as you move through thebook. Along the way you’ll get the scoop on organizing yourdata, object-oriented programming (also known as OOP), and a greatLINQ-related feature called delegates and events. You’ll findout how to

Create a console application template Perform logical comparisons Work with loops and if statements Understand collection syntax Use interfaces and object-oriented concepts Apply delegates and events, and much more

You’ll even gain some rare insight into how to understanderror messages you may get when programming in C#. All the code youneed can be found on the companion Web site, along with great bonusinformation that helps you do more with C# 2008. So — whatare you waiting for? Grab C# 2008 For Dummies andlet’s get started!

Whether you’re a total novice or a programmer shifting to C#,the newest version of this programming language is full of coolfeatures you’ll want to use. With its Visual Studiocompatibility, C# is the perfect language for building WindowsVista applications. And the 2008 version works with LINQ, a querylanguage with syntax similar to SQL but which simplifies databasecode and can also write queries on XML files.

For the best basic C# how-to, it’s hard to beat C# 2008For Dummies. This plain-English guide to programming with C#can have you creating your first console application before youfinish Part I. In fact, the basic template you create at that pointwill be the foundation of many other apps as you move through thebook. Along the way you’ll get the scoop on organizing yourdata, object-oriented programming (also known as OOP), and a greatLINQ-related feature called delegates and events. You’ll findout how to

Create a console application template Perform logical comparisons Work with loops and if statements Understand collection syntax Use interfaces and object-oriented concepts Apply delegates and events, and much more

You’ll even gain some rare insight into how to understanderror messages you may get when programming in C#. All the code youneed can be found on the companion Web site, along with great bonusinformation that helps you do more with C# 2008. So — whatare you waiting for? Grab C# 2008 For Dummies andlet’s get started!

More info:

Publish date: Apr 26, 2013
Added to Scribd: May 14, 2013
Copyright:Traditional Copyright: All rights reservedISBN:9780470294109
List Price: $29.99 Buy Now

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
This book can be read on up to 6 mobile devices.
See more
See less

02/17/2015

458

9780470294109

$29.99

USD

You're Reading a Free Preview
Pages 10 to 49 are not shown in this preview.
You're Reading a Free Preview
Pages 59 to 283 are not shown in this preview.
You're Reading a Free Preview
Pages 293 to 359 are not shown in this preview.
You're Reading a Free Preview
Pages 369 to 406 are not shown in this preview.
You're Reading a Free Preview
Pages 416 to 458 are not shown in this preview.

You're Reading a Free Preview

Download
scribd