Introducing Visual C# 2010 (eBook)
XXXIV, 1320 Seiten
Apress (Verlag)
978-1-4302-3172-1 (ISBN)
The book gradually builds up your knowledge, using the concepts you have already grasped to support those that come next. You will explore all the core areas of the C# language and the .NET Framework on which it runs. Particular attention is paid to the creation of Web and Windows applications and data access-danger zones where novice programmers often go awry in their early coding attempts.
Introducing Visual C# 2010 is a comprehensive primer. Even if you have no previous programming experience, you can have confidence in the fact that you'll be able to build well constructed web and Windows applications of your own once you have finished reading this book.
Adam Freeman is an experienced IT professional who has held senior positions in a range of companies, most recently serving as chief technology officer and chief operating officer of a global bank. Now retired, he spends his time writing and long-distance running.
If you're new to C# programming, this book is the ideal way to get started. Respected author Adam Freeman guides you through the C# language by carefully building up your knowledge from fundamental concepts to advanced features. The book gradually builds up your knowledge, using the concepts you have already grasped to support those that come next. You will explore all the core areas of the C# language and the .NET Framework on which it runs. Particular attention is paid to the creation of Web and Windows applications and data access-danger zones where novice programmers often go awry in their early coding attempts. Introducing Visual C# 2010 is a comprehensive primer. Even if you have no previous programming experience, you can have confidence in the fact that you'll be able to build well constructed web and Windows applications of your own once you have finished reading this book.
Adam Freeman is an experienced IT professional who has held senior positions in a range of companies, most recently serving as chief technology officer and chief operating officer of a global bank. Now retired, he spends his time writing and long-distance running.
Title Page 1
Copyright Page 2
Contents at a Glance 4
Table of Contents 6
About the Authors 32
About the Technical Reviewers 33
Acknowledgments 34
PART 1 Getting Started 35
Chapter 1 Introduction 36
Who Should Read This Book? 36
What Is Covered in This Book? 36
What Do You Need to Read This Book? 37
What Is the Structure of This Book? 37
What Is in Each Chapter? 37
Getting the Example Code 39
Finding More Information 39
The MSDN C# Programming Guide 39
Online Forums 39
Other Books 39
Summary 39
Chapter 2 Getting Ready 40
Installing the Software 40
Installing Visual Studio 2010 40
Installing SQL Server 2008 42
Installing the Silverlight Tools 43
Downloading the Sample Code and Data 43
Creating Your First C# Project 43
Creating the Project 44
Editing the Code 46
Compiling and Running the Program 47
Features That I Use Before Explaining Them 47
The using statements 47
The namespace statement 48
The class statement 48
The Main method 48
The Code Comments 49
The Console.WriteLine and Console.ReadLine methods 49
Summary 49
Chapter 3 Understanding C# and the .NET Framework 50
C# and the .NET Framework at a Glance 50
Introducing C# 50
Introducing the .NET Framework 51
Introducing the Common Language Runtime 51
Introducing the Class Library 51
The Relationship between C# and the .NET Framework 52
Using C# Code Files 52
Understanding Assemblies 53
The Key Features of C# and the .NET Framework 55
Understanding Object-Orientation 55
Understanding Type Safety 55
Understanding Automatic Memory Management 56
Understanding the Just-In-Time Compiler 56
Understanding Parallel Processing 56
Understanding Unmanaged/Native Code Support 57
Understanding the .NET Technology Spectrum 57
Understanding ASP.NET 59
Understanding LINQ 59
Understanding the Task Parallel Library 60
Understanding User Interfaces 60
Understanding ADO.NET 61
Understanding the Windows Communication Foundation 62
Understanding .NET Cross-Platform Support 62
Summary 63
PART 2 The C# Language 64
Chapter 4 C# Fundamentals and Keyword Reference 66
Language Fundamentals 66
A Simple C# Program 66
C# Syntax 67
Identifiers 67
Keywords 70
Literals 70
Operators 71
Punctuators 72
Statements 73
Comments 73
Types 74
Value Types 75
Reference Types 76
Definite Assignment and Null References 78
Common Programming Tasks 79
Assigning Values 79
Making Comparisons 80
Performing Selections 82
Using an if Statement 82
Using a switch Statement 84
Iterating Data Items 86
Using a for Loop 86
Using a foreach Loop 89
Using a do...while Loop 91
Using a while Loop 92
Keyword and Operator Reference 93
Type Keywords 94
bool 95
byte, sbyte 95
char 95
class 96
decimal, double, float 96
delegate 97
dynamic 97
enum 98
interface 98
object 99
string 100
struct 100
short, ushort, int, uint, long, ulong 101
void 101
var 102
Modifiers 102
public, protected, private, internal 102
abstract 104
const 104
event 104
in, out 105
override 106
readonly 106
sealed 107
static 107
virtual 108
Selection Keywords 108
if, else 108
switch, case, default 108
Iterator Keywords 108
for 109
foreach 109
do, while 109
Jump Keywords 109
break 109
continue 109
goto 110
return 110
Exception Handling Keywords 110
throw 110
try, catch, finally 111
Arithmetic Overflow Keywords 111
checked, unchecked 111
Synchronization Keywords 112
lock 112
Parameter Keywords 112
params 112
ref 113
out 114
Namespace Keywords 114
namespace 114
using 115
Literal Keywords 115
null 115
true, false 116
Object Keywords 116
is, as 116
new 116
typeof 117
LINQ Keywords 117
Other Keywords 117
base 117
get, set, value 118
global 118
implicit, explicit 118
operator 119
partial 119
using 119
this 119
yield 119
Operators 120
[ ] Operator 120
( ) Operator 120
Dot (.) Operator 120
:: Operator 120
+, -, *, /, % Operators 121
==, !=, > , >
++, +=, --, -= Operators 121
& &
& , |, ^, ~, <
=> Operator
=, +=, -=, *=, /=, %=, & =, >
Summary 122
Chapter 5 Numeric and Boolean Types 123
Numeric Types 124
Using Numeric Literals 125
Using Literal Suffixes 127
Using Literal Prefixes 128
Implicit and Explicit Numeric Type Conversions 130
Using Overflow Checking 133
Using Struct Members 135
Common Members 135
Using Type-Specific Members 139
Using Numeric Operators 141
Arithmetic Operators 141
Unary Operators 145
Relational Operators 148
Logical Operators 150
Assignment Operators 154
Working with Very Large Integer Values 158
The Boolean Type 159
Using Boolean Literals 159
Using Boolean Results 160
Using Struct Members 161
Summary 162
Chapter 6 Classes and Objects 163
Creating a Basic Class 164
Adding Features to a Class 165
Adding Fields 165
Adding Methods 166
Adding a Constructor 167
Creating Objects from Classes 168
Using Objects 171
Reading and Modifying Fields 172
References to Common Objects 174
Using Static Fields 179
Calling Methods 180
Class Inheritance 182
Understanding Inheritance 185
Overriding Methods 188
Inheriting Derivations 189
Understanding Encapsulation 191
Understanding Polymorphism 192
Casting Objects and Type Checking 197
Implicit vs. Explicit Casting 197
Type Conversion Exceptions 201
Avoiding Explicit Cast Exceptions 202
Testing an Object’s Type 202
Casting Without Exceptions 204
Boxing and Unboxing 205
Using Nested Classes 207
Using Class Modifiers 208
Creating Static Classes 208
Creating Abstract Classes 210
Creating Sealed Classes 211
Creating Partial Classes 211
Using Access Modifiers 212
Summary 213
Chapter 7 Fields 214
Defining and Using Fields 215
Defining Fields 215
Initializing Fields 215
Reading and Updating Fields 217
Working Directly with Field Values 218
Allowing Other Classes to Read and Modify Properties 219
Exposing Properties with Field Values 220
Understanding Reference Type Fields 223
The Fourth Stage of the Life Cycle 224
Applying Field Modifiers 225
Creating Static Fields 225
Creating Read-Only Fields 227
Using the const keyword 227
Using the readonly Keyword 228
Applying Access Modifiers 230
Hiding Base Class Fields 230
Using the volatile Keyword 232
Summary 232
Chapter 8 Properties, Indexers, and Operators 233
Creating a Property 234
Creating a Field-Backed Property 234
Using a Property 237
Creating an Automatically Implemented Property 238
Creating an Asymmetric Property 239
Creating a Computed Property 239
Mapping a Property Type to a Field Type 240
Using Access Modifiers 240
Using Other Modifiers 241
Using the virtual and override Modifiers 242
Using the abstract Modifier 243
Using the sealed Keyword 243
Using the static Keyword 244
Creating an Indexer 245
Using Multiple Indexers 246
Creating a Validating Indexer 247
Creating an Indexer with Multiple Arguments 248
Creating Custom Operators 249
Creating Custom Unary Operators 249
Creating Custom Binary Operators 251
Creating Custom Conversion Operators 255
Summary 257
Chapter 9 Methods 258
Creating and Using a Simple Method 260
Defining the Method Name 261
Defining the Result Type 261
Defining the Parameters 262
Defining the Modifiers 263
Defining the Method Body 266
Using the Methods 267
Understanding Parameters 268
Using Value Parameters 268
Using Reference Parameters 272
Using Output Parameters 274
Using Parameter Arrays 276
Using Optional Parameters 278
Using Named Parameters 279
Understanding Method Bodies 280
Using Local Variables 280
Naming Variables 282
Understanding Variable Scope and Lifetime 284
Using Method Results 285
Understanding Method Modifiers 286
Using Access Modifiers 286
Creating Static Methods 286
Creating Virtual Methods 287
Creating Sealed Methods 287
Creating Abstract Methods 288
Overloading Methods 288
Hiding and Overriding Methods 291
Hiding Methods 292
Overriding Methods 294
Sealing Methods 296
Understanding Method Specialization 297
Special Methods 298
The Main Method 298
Constructors 301
Using the Default Constructor 303
Initializing Properties and Fields at Construction 303
Overloading Constructors 304
Calling Base Class Constructors 309
Controlling Access to Constructors 312
Creating Copy Constructors 313
Using Static Constructors 316
Creating Factory Methods 318
Destructors 319
Iterator Blocks 320
Using the yield Keyword 321
Exposing Field Iterators 322
Using Multiple yield Statements 323
Using Named Iterator Blocks 324
Partial Methods 325
Abstract Methods 328
Extension Methods 330
Summary 333
Chapter 10 Delegates, Events, and Anonymous Methods 334
Using Delegates 335
Using Delegates for Callbacks 337
Multicasting with Delegates 339
Delegating Selectively 341
Interrogating Delegates 342
Using Events 344
Defining and Publishing EventHandler Pattern Events 346
Creating Nongeneric Events 351
Creating Events Without Custom Data 352
Applying Modifiers to Events 354
Using Action and Func Delegates 355
Using Action Delegates 355
Using Func Delegates 357
Anonymous Methods 358
Capturing Outer Variables 360
Lambda Expressions 363
Summary 365
Chapter 11 Namespaces 366
Consuming Namespaces 366
Using Fully Qualified Names 367
Importing Namespaces 368
Creating Namespaces 369
Nesting Namespaces 371
Logically Nesting Namespaces 372
Spreading Namespaces Across Files 373
Adding Types to Existing Namespaces 375
Disambiguating Namespaces and Types 376
Disambiguation with Fully Qualified Names 378
Disambiguating with Aliases 378
Aliasing Namespaces 379
Resolving Type or Namespace Hiding 380
Summary 382
Chapter 12 Interfaces, Structs, and Enums 383
Using Interfaces 384
Defining and Using a Simple Interface 384
Defining an Interface 384
Implementing an Interface 385
Using an Interface 386
Specifying Interface Members 386
Specifying Methods 387
Specifying Properties 387
Specifying an Event 389
Specifying an Indexer 390
Deriving Interfaces 390
Deriving from Multiple Base Interfaces 391
Defining a Partial Interface 393
Implementing Interfaces 393
Implementing Multiple Interfaces 394
Explicitly Implementing an Interface 395
Inheriting Interface Implementations 397
Implementing an Interface in an Abstract Class 398
Using Structs 399
Defining and Instantiating a Struct 399
Implementing Interfaces 401
Differences Between Structs and Classes 402
Base Structs and Inheritance 403
Defining Fields 403
Defining a Struct Constructor 403
Copying a Struct 404
Using an Enum 408
Defining an Enum 408
Using an Enum 409
Using Underlying Types and Numeric Values 410
Combining Enum Values 411
Summary 412
Chapter 13 Arrays 413
Defining and Initializing Arrays 415
Getting and Setting Array Values 417
Using Array Initializers 419
Enumerating Arrays 421
Enumerating with a for Loop 421
Enumerating with a foreach Loop 423
Enumerating Using IEnumerator and IEnumerator< T>
Breaking from Enumerations 426
Using System.Array Members 428
Sorting Arrays 428
Processing All of the Elements in an Array 429
Resizing and Copying an Array 430
Finding Items in an Array 434
Using Arrays with LINQ 436
Using Arrays as Collections 437
Using Multidimensional Arrays 437
Using Rectangular Arrays 438
Getting and Setting Rectangular Array Values 439
Using Rectangular Array Initializers 439
Enumerating a Rectangular Array 440
Creating Rectangular Arrays with Additional Dimensions 442
Using Jagged Arrays 443
Getting and Setting Jagged Array Values 444
Using Jagged Array Initializers 445
Enumerating a Jagged Array 445
Summary 446
Chapter 14 Exceptions 447
Handling Exceptions 448
Using try Statements and catch Clauses 449
Handling Different Exception Types 452
Using Specific catch Clauses 453
Using General catch Clauses 454
Omitting catch Clauses 454
Nesting try Statements 455
Using Exception Members 455
Using finally Clauses 458
Throwing Exceptions 460
Rethrowing Exceptions 464
Creating and Throwing Custom Exceptions 466
Throwing Meaningful Exceptions 469
Mapping One Exception Type to Another 470
Creating Exception Chains 472
Aggregating Exceptions 474
Summary 479
Chapter 15 Generic and Anonymous Types 480
Using Generic Types 481
Defining a Generic Class 483
Creating Objects from Generic Classes 483
Implementing and Using Generic Class Members 484
Defining Multiple Parameter Types 487
Casting from Parameterized Types 488
Constraining Parameterized Types 489
Applying Multiple Constrains to a Parameterized Type 491
Constraining Multiple Parameterized Types 492
Defining a Method-Specific Parameterized Type 492
Deriving from a Generic Base Class 494
Inheriting Type Deferral 494
Specifying Parameterized Types 497
Creating Generic Interfaces 498
Creating Generic Structs 499
Type Variance 499
Covariance 502
Contravariance 503
Combining Contravariance and Covariance 504
Using the default Keyword 504
Using Anonymous Types 505
Summary 507
Chapter 16 Strings and Characters 508
Working with Characters 509
Expressing Characters Using Literals 509
Performing Operations on Characters 510
Using Struct Members 511
Using Strings 513
Expressing Strings Using String Literals 513
Using String Escape Sequences and Verbatim Literals 514
Performing Operations on Strings 515
Comparing Strings 516
Combining Strings 518
Reading Individual Characters 519
Enumerating a String 520
Using Strings in a switch Statement 521
Using Regular Expressions 522
Using Class Members 523
Manipulating Strings 523
Searching Strings 526
Other Class Members 527
Using the StringBuilder Class 529
Creating a StringBuilder Object 529
Using a StringBuilder Object 529
Using the Append and Insert Methods 532
Using the StringBuilder Indexer 533
Formatting Strings 534
Using Composite Formatting 534
Other Composite Formatting Methods 535
Specifying Alignment 536
Escaping Braces 537
Formatting Types 538
Using a Format Component 538
Creating String Representations of Custom Types 541
Performing Custom Composite Formatting 543
Summary 545
Chapter 17 Attributes 546
Using Attributes 546
Applying Attributes with Parameters 548
Testing for an Attribute 549
Testing for an Attribute Applied to a Class 549
Testing for an Attribute Applied to a Field 552
Testing for an Attribute Applied to a Property 555
Testing for an Attribute Applied to a Method 557
Creating a Custom Attribute 559
Using a Custom Attribute 560
Defining Properties in a Custom Attribute 562
Controlling How a Custom Attribute Can Be Used 562
Controlling Attribute Inheritance 564
Summary 565
Chapter 18 Garbage Collection 566
Explicitly Running the Garbage Collector 567
Implementing a Destructor 568
Destructors vs. Finalizers 569
Problems with Destructors 570
Performance Impact 570
Uncertain Execution 570
Uncertain Ordering 570
Using Disposal 571
Using Weak References 573
Summary 574
PART 3 The .NET Class Library 575
Chapter 19 Collections 577
The ICollection< T>
Generic Lists 580
The IList< T>
The List< T>
Adding, Retrieving, and Removing Items 583
Finding List Items 585
Sorting List Items 591
Processing Items 597
Other List< T>
The LinkedList< T>
Adding, Retrieving, and Removing Items 602
Finding List Items 606
The SortedList< TKey, TVal>
Adding, Retrieving, and Removing Items 608
Other SortedList< TKey, TVal>
Generic Dictionaries 611
The IDictionary< TKey, TVal>
The KeyValuePair< TKey, TVal>
The Dictionary< TKey, TVal>
Adding, Retrieving, and Removing Items 616
Other Dictionary< TKey, TVal>
The SortedDictionary< TKey, TVal>
Generic Sets 621
The ISet< T>
The HashSet< T>
The SortedSet< T>
Generic Queues and Stacks 628
The Queue< T>
The Stack< T>
Other Generic Collection Interfaces 632
The IComparer< T>
The IEqualityComparer< T>
Treating Arrays as Collections 635
Creating Constrained Collections 639
Read-Only Lists 639
Other Read-Only Collections 640
Legacy Collections 643
Summary 645
Chapter 20 Files, Streams, and IO 646
Working with Files and Directories 647
Using the System.IO.Directory Class 647
Enumerating Files and Directories 647
Getting and Setting Information for a File or Directory 653
Changing the Current Working Directory 654
Using the FileInfo and DirectoryInfo Classes 655
Using the FileInfo Class 656
Using the DirectoryInfo Class 659
Using the System.IO.File Class 664
Using the File Convenience Methods 665
Using the Stream, Reader, and Writer Methods 667
Using the System.IO.Path Class 668
Monitoring for Changes 670
Filtering the Monitored Files and Directories 673
Filtering the Triggers for a Change Event 674
Working with Streams, Readers, and Writers 675
Using Streams 675
Using the System.IO.Stream Class (in Detail) 678
Using Base Streams 682
Using Pass-Through Streams 688
Using Readers and Writers 691
Reading and Writing Binary Data 692
Reading and Writing Textual Data 695
Summary 698
Chapter 21 Networking & WCF
Requesting Data 699
Using WebClient Members to Configure a Request 701
Using WebClient Members to Retrieve Data 703
Getting the WebClient Response Headers 704
Using WebClient Events 706
Programming with Sockets 708
Creating a Simple TCP Client & Server
Creating the Server 709
Creating the Client 713
Writing a Parallel Server 715
The Windows Communication Foundation 717
Creating the WCF Server 718
Creating the Service Contract 718
Creating the WCF Client 721
Other Useful Network Classes 724
Writing a Simple Web Server 724
Using Connectionless Networking 728
Using the Domain Name System 731
Summary 733
Chapter 22 Time & Dates
Measuring Small Amounts of Time 735
Working with Periods of Time 738
Creating and Using TimeSpan Values 738
Performing Operations on TimeSpan Values 742
Formatting TimeSpan Strings 743
Creating Custom TimeSpan Format Strings 744
Working with Particular Dates and Times 746
Creating and Using DateTime Values 747
Performing Operations on DateTime Values 750
Formatting DateTime Strings 753
Creating Custom DateTime Format Strings 754
Summary 756
Chapter 23 Serialization 757
Using Binary Serialization 758
Serializing Graphs of Objects 761
Serializing Multiple Objects to a Single Stream 763
Selectively Serializing Fields 766
Using Serialization Callbacks 767
Version Tolerance 770
Adding Tolerance for Specific Changes 773
Using SOAP Serialization 774
Version Tolerance 776
Serializing Generic Objects 777
Using XML Serialization 777
Selectively Serializing Fields 779
Mapping Members to Elements and Attributes 780
Changing the Name for Attributes and Elements 781
Using Data Contract Serialization 782
Preparing a Class for Data Contract Serialization 782
Generating Portable XML 783
Generating .NET-specific XML 784
Generating JSON 786
Summary 787
Chapter 24 Serialization 788
Understanding Single- and Multi-Threaded Execution 789
Getting Started with Tasks 793
Creating a Task 793
Starting a Task 794
Waiting for a Task 795
Getting Results from Tasks 797
Passing Parameters to a Task 799
Getting the Status of a Task 801
Using the Status Properties 803
Canceling Tasks 803
Checking and Throwing in a Single Statement 805
Cancelling Multiple Tasks 807
Handling Task Exceptions 808
Handling an Exception in a Task Body 808
Handling an Exception from a Trigger Method 810
Handling Exceptions from Multiple Tasks 811
Dealing with Exceptions using Task Properties 813
Using a Custom Exception Escalation Policy 815
Chaining Tasks Together 817
Creating a Simple Continuation 817
Getting Details of the Antecedent 818
Providing a Continuation Result 819
Creating Chains of Continuations 821
Creating Selective Continuations 822
Sharing Data between Tasks 824
Understanding a Critical Region 827
Creating a Critical Region 827
Avoiding Synchronization 829
Using Concurrent Collections 830
Summary 834
Chapter 25 Asynchronous Methods and Parallel Loops 835
Using Asynchronous Methods 836
Using Pre-Built Asynchronous Methods 836
Asynchronously Calling Any Method 839
Waiting for an Asynchronous Method to Complete 840
Mixing Asynchronous Methods and Tasks 843
Using Parallel Loops 844
Creating a Parallel ForEach Loop 844
Creating a Parallel For Loop 846
Breaking and Stopping Parallel Loops 847
Summary 851
Chapter 26 Other Useful Features and Classes 852
Converting Between Types 853
Returning Multiple Results from Methods Using Tuples 855
Aliasing Generic Types 858
Using Nullable Types 860
Using the Null-Coalescing Operator 861
Working with the Console 862
Reading from and Writing to the Console 862
Making the Console Beep 865
Modifying the Appearance of the Console 865
Generating Random Numbers 867
Converting Strings to and from Bytes 868
Getting Environment Information 869
Performing Math Operations 871
Using Conditional Compilation 872
Using Visual Studio to Define Symbols 874
Conditionally Compiling Methods 875
Checking Network Connectivity 877
Listening for Connectivity Changes 878
Summary 879
PART 4 Data and Databases 880
Chapter 27 LINQ to Objects 881
Performing a Simple LINQ Query 882
Understanding LINQ to Objects Data Sources 884
Enumerating Results Manually 885
Using Results as Data Sources 886
Understanding Query Results 888
The Range Variable Type 888
The Result Type 888
Explicitly Specifying the Range Variable Type 890
Letting the Compiler Infer Types 891
Performing LINQ Operations 892
Filtering Data 893
Projecting Data 894
Projecting a Single Member 895
Projecting Anonymous Types 896
Projecting Derived Data 897
Ordering Data 899
Grouping Data 903
Grouping Using a Boolean Value 905
Grouping Using an Anonymous Type 907
Querying Grouped Data 908
Using Method Syntax 909
Understanding Deferred Execution 913
Reusing Queries 913
Referring to Variables 914
Forcing Immediate Execution 915
Converting Query Results 917
Using Legacy Collections as LINQ Data Sources 920
Explicitly Specifying the Range Variable Type 920
Using Cast and OfType Extension Methods 921
Performing Advanced LINQ Operations 923
Aggregating Data 923
Joining Data 925
Creating Combinations of Data 928
Creating Additional Range Variables 929
Summary 931
Chapter 28 Parallel LINQ 932
Performing a Parallel LINQ Query 932
Understanding PLINQ Result Ordering 935
Preserving Order in a PLINQ query 937
Forcing Parallel Execution 938
Performing Queries without Results 939
Summary 940
Chapter 29 LINQ to XML 941
Using the LINQ XML Classes 942
Creating XML Declaratively 942
Using Arbitrary Types to Create XElements 944
Creating Other XML Node Types 946
Creating Valid XML Documents 948
Populating an XElement or XDocument with an IEnumerable 949
Reading and Writing XML Files 950
Saving XML 950
Loading XML 952
Processing XML Declaratively 952
Filtering Elements by Name 954
Finding All Descendants 955
Modifying XML 956
Using LINQ to XML Queries 960
Querying XML for Data 961
Creating XML from LINQ Queries 962
Create Objects from XML 965
Modifying and Transforming XML Data 966
Adding Elements to XML 966
Creating a CSV File from XML 968
Creating XML from CSV Data 969
Changing and Deleting Elements 971
Sorting XML 973
Grouping XML 974
Using Parallel LINQ to Process XML 976
Summary 979
Chapter 30 LINQ to Entities 980
Getting Ready 981
Preparing the Database 982
Creating the Model 982
Using LINQ to Entities 988
Using the Data Model Context 989
Using Table Properties and Row Objects 990
Understanding the IQueryable< T>
Enumerating the Results 993
Navigating Using Foreign Key Relationships 994
Querying Using Navigation Properties 997
Using Navigation Data Efficiently 998
Performing Common Database Operations 1000
Querying Data 1000
Compiling Queries 1000
Querying Views 1003
Querying Stored Procedures 1004
Inserting Data into the Database 1008
Inserting Attached Objects 1010
Updating Data in the Database 1011
Deleting Data 1013
Enabling Concurrency Checking 1014
Summary 1015
Chapter 31 LINQ to DataSet 1016
Connecting to and Querying a Database 1017
Setting Up the Database 1017
Creating a Connection to the Database 1019
Storing Connection Strings 1023
Executing a SQL Query 1025
Understanding the DataSet Class 1027
Enumerating Results with DataTable and DataRow Objects 1029
Querying DataSets with LINQ 1031
Perform Joins on a DataSet 1033
Comparing Data 1036
Querying for Data Intersects 1036
Subtracting Results 1038
Performing Database Operations Using Cached Data 1039
Inserting Data 1039
Modifying Data 1042
Deleting Data 1044
Summary 1045
PART 5 User Interfaces 1046
Chapter 32 Windows Forms 1048
Building a Stand-Alone Window Forms Program 1048
Creating the Project 1049
Adding the Controls 1051
Setting the Control Properties 1053
Configuring the Labels 1053
Configuring the TextBoxes and NumericUpDowns 1054
Configuring the Button 1056
Adding the MenuStrip and StatusStrip 1056
Setting the Control Names 1058
Setting the Tab Order 1060
Wiring the Controls 1060
Wiring the Quit Menu 1061
Wiring the TextBoxes 1063
Wiring the Button 1066
Setting the Icon 1068
Testing the Program 1068
Using Windows Forms Data Binding 1068
Creating the Project and Creating the Data Model 1068
Creating and Using the Object Data Source 1069
Formatting the Grid Control 1071
Loading the Data 1073
Wiring the Save Button 1073
Testing the Program 1074
Two Program Variations 1075
Filtering the Data with LINQ 1075
Displaying Data Fields 1076
Windows 7 UI Integration 1078
Using Aero Glass 1078
Summary 1081
Chapter 33 Windows Presentation Foundation 1083
Building a Stand-Alone WPF Program 1083
Creating the Project 1083
Adding the Controls 1086
Setting the Control Properties 1088
Configuring the Label Controls 1088
Configuring the TextBox Controls 1088
Configuring the TextBlock Control 1089
Configuring the Button 1090
Adding the StatusBar Item 1090
Adding the StatusBar Item 1091
Adding the Menu Item 1091
Setting the Tab Order 1091
Wiring the Controls 1092
Wiring the Quit Menu 1092
Wiring the TextBox Controls 1093
Wiring the Button 1094
Managing the Focus 1095
Focusing on the First Control 1095
Selecting the TextBox Text on Focus 1096
Setting the Program Icon and Window Name 1096
Testing the Program 1096
Using WPF Data Binding 1097
Formatting the DataGrid Control 1098
Loading the Data 1099
Wiring the Button 1099
Testing the Program 1100
Using WPF-Specific Features 1100
Using WPF Animations 1100
Creating the Project 1101
Adding the Animation 1101
Testing the Animation 1103
Combining Multiple Animations 1103
Using WPF Commands 1104
Creating the Project 1104
Configuring the Button Controls 1105
Adding and Configuring the MenuItem Control 1106
Binding the Command 1106
Selectively Activating the Command 1108
Using Commands to Set Control Content 1110
Summary 1138
Chapter 34 ASP.NET 1113
Building a Web Forms Program 1113
Creating the Project 1113
Adding the Controls 1116
Setting the Control Properties 1118
Configuring the Labels 1118
Configuring the TextBox Controls 1118
Configuring the Button 1120
Setting the Tab Order 1120
Wiring the Button Control 1121
Setting the Focus 1121
Testing the Program 1122
Using Web Forms Data Binding 1122
Create the Project and the Entity Data Model 1123
Adding the Web Form 1123
Creating the Web Forms Data Source 1123
Adding the GridView Control 1125
Testing the Program 1126
Using ASP.NET Dynamic Data 1127
Creating the Project 1127
Creating the Entity Data Model 1128
Registering the Data Model 1128
Testing the Program 1128
Customizing a Dynamic Data Application 1130
Changing the Name of a Table 1131
Changing the Name and Visibility of a Column 1133
Selecting Tables to Be Displayed 1134
Customizing the Display Template 1136
Summary 1138
Chapter 35 Silverlight 1139
Creating the Swimming Calculator 1140
Creating the Project 1140
Defining the Layout 1142
Adding Grid Columns 1142
Adding the StackPanel Controls 1144
Adding the TextBox Controls 1145
Adding the Label Controls 1146
Adding the TextBlock Control 1147
Adding the Button Control 1148
Adjusting the Layout 1149
Wiring the Button 1150
Adding a Child Window 1151
Using a WCF RIA Service 1154
Creating the Project 1155
Creating the Data Model 1155
Creating the Domain Service Class 1156
Creating the Silverlight Client 1158
Adding the Data 1159
Configuring the DataGrid Control 1159
Configuring the ComboBox Control 1160
Wiring the ComboBox Control 1161
Testing the Application 1163
Using Silverlight Out-of-Browser Support 1163
Configuring the Out-of-Browser Support 1164
Using a Silverlight Program Out-of-Browser 1166
Making Installation Part of the Interface 1167
Using Other Out-of-Browser Features 1171
Summary 1171
PART 6 Advanced Topics 1172
Chapter 36 Windows Integration 1173
Using the Windows Event Log 1173
Reading an Event Log 1174
Writing to an Event Log 1177
Creating the Event Source 1177
Writing Events 1178
Using Elevated Privileges 1179
Creating a Windows Service 1181
Creating the Service Class 1182
Adding the Service Functionality 1184
Adding the Service Installer 1186
Add the MSI Installer 1187
Installing the Service 1189
Creating the Client 1191
Using the Windows Registry 1191
Searching the Registry 1191
Reading and Modifying the Registry 1194
Summary 1195
Chapter 37 Cryptography and Security 1196
Encrypting and Decrypting Data 1197
Creating and Using Encryption Keys 1197
Encrypting Data 1200
Decrypting Data 1201
Using the Windows Data Protection API 1202
Using Hash Codes 1204
Generating a Hash Code 1205
Verifying a Hash Code 1207
Generating Secure Random Numbers 1208
Working Securely with Strings 1209
Summary 1211
Chapter 38 Testing and Debugging 1212
Using the Debug and Trace Classes 1213
Using the Debug Class 1213
Making Assertions 1215
Disabling Debug Statements 1217
Using Debug Listeners 1218
Other Debug Methods 1220
Using the Trace Class 1223
Using Static Code Analysis 1225
Selecting the Code Analysis Rules 1225
Performing Static Analysis 1226
Dealing with a Rule Violation 1227
Suppressing a Single Occurrence 1228
Suppressing Every Occurrence 1230
Using Code Contracts 1232
Installing and Enabling Code Contract Support 1232
Writing Code Contracts 1233
Using Precondition Contracts 1233
Using Postcondition Contracts 1234
Using Assertion Contracts 1235
Using Invariant Contracts 1236
Using the Static Checker 1237
Using the Runtime Checker 1240
Summary 1241
Index 1242
Erscheint lt. Verlag | 27.1.2011 |
---|---|
Zusatzinfo | XXXIV, 1320 p. |
Verlagsort | Berkeley |
Sprache | englisch |
Themenwelt | Informatik ► Software Entwicklung ► Objektorientierung |
Mathematik / Informatik ► Informatik ► Theorie / Studium | |
Mathematik / Informatik ► Informatik ► Web / Internet | |
Schlagworte | ADA • ASP • ASP.NET • Boo • C# • .NET • .NET Framework • SQL • Visual C# |
ISBN-10 | 1-4302-3172-6 / 1430231726 |
ISBN-13 | 978-1-4302-3172-1 / 9781430231721 |
Haben Sie eine Frage zum Produkt? |
![PDF](/img/icon_pdf_big.jpg)
Größe: 23,2 MB
DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasserzeichen und ist damit für Sie personalisiert. Bei einer missbräuchlichen Weitergabe des eBooks an Dritte ist eine Rückverfolgung an die Quelle möglich.
Dateiformat: PDF (Portable Document Format)
Mit einem festen Seitenlayout eignet sich die PDF besonders für Fachbücher mit Spalten, Tabellen und Abbildungen. Eine PDF kann auf fast allen Geräten angezeigt werden, ist aber für kleine Displays (Smartphone, eReader) nur eingeschränkt geeignet.
Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.
Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.
Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.
aus dem Bereich