Sams Teach Yourself C# 5.0 in 24 Hours Scott J. Dorman 800 East 96th Street, Indianapolis, Indiana, 46240 USA Sams Teach Yourself C# 5.0 in 24 Hours Copyright © 2013 by Pearson Education All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). ISBN-13: 978-0-672-33684-3 ISBN-10: 0-672-33684-7 The Library of Congress Cataloging-in-Publication data is on file. Printed in the United States of America First Printing November 2012 Editor-in-Chief Greg Wiegand Executive Editor Neil Rowe Development Editor Mark Renfrow Managing Editor Kristy Hart Project Editor Betsy Harris Copy Editor Karen Annett Indexer Christine Karpeles Proofreader Debbie Williams Technical Editor Christopher Wilcox Publishing Coordinator Cindy Teeters Cover Designer Anne Jones Compositor Nonie Ratcliff Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark. Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an “as is” basis. The author and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book. Bulk Sales Sams Publishing offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales. For more information, please contact U.S. Corporate and Government Sales 1-800-382-3419 [email protected] For sales outside of the U.S., please contact International Sales [email protected] Contents at a Glance Introduction Part I: C# Fundamentals Hour 1 The .NET Framework and C# 2 Introducing Visual Studio 3 Understanding C# Types 4 Understanding Classes and Objects the C# Way 5 Inheritance, Interfaces, and Abstract Classes 6 Creating Enumerated Types and Structures 7 Events and Event Handling Part II: Programming in C# Hour 8 Controlling Program Flow 9 Using Strings and Regular Expressions 10 Working with Arrays and Collections 11 Handling Errors Using Exceptions 12 Understanding Generics 13 Understanding Query Expressions Part III: Working with Data Hour 14 Using Files and Streams 15 Working with XML 16 Working with Databases Part IV: Building an Application Using Visual Studio Hour 17 Building a Windows Application 18 Using Data Binding and Validation 19 Building Windows Store Apps 20 Building a Web Application Part V: Diving Deeper Hour 21 Programming with Attributes 22 Dynamic Types and Language Interoperability 23 Memory Organization and Garbage Collection 24 Understanding Threads, Concurrency, and Parallelism Index Table of Contents Introduction Part I: C# Fundamentals Hour 1: The .NET Framework and C# The .NET Framework The C# Language Summary Q&A Workshop Exercises Hour 2: Introducing Visual Studio Introducing the Visual Studio Editions Writing Your First Program Debugging in Visual Studio Visualizing Data Commenting Your Code Summary Q&A Workshop Exercises Hour 3: Understanding C# Types An Overview of Types The C# Predefined Types Other Commonly Used Types Working with Operators Default Values Null and Nullable Types Casting and Conversion Summary Q&A Workshop Exercises Hour 4: Understanding Classes and Objects the C# Way Object-Oriented Programming Component-Oriented Programming Classes in C# Scope and Declaration Space Nested Classes Partial Classes Static Classes Object Initializers Summary Q&A Workshop Exercises Hour 5: Inheritance, Interfaces, and Abstract Classes Inheritance and Polymorphism Abstract Classes and Members Working with Interfaces Summary Q&A Workshop Exercises Hour 6: Creating Enumerated Types and Structures Enumerated Types Working with Structures Summary Q&A Workshop Exercises Hour 7: Events and Event Handling Understanding Events Subscribing and Unsubscribing Publishing an Event Raising an Event Summary Q&A Workshop Exercises Part II: Programming in C# Hour 8: Controlling Program Flow Understanding the Selection Statements Iteration Statements Jump Statements Summary Q&A Workshop Exercises Hour 9: Using Strings and Regular Expressions Strings Mutable Strings Using StringBuilder Type Formatting Regular Expressions Summary Q&A
Description: