C# Prog AbsBeg-00Fnt.qxd 2/22/03 6:55 PM Page i Microsoft ® C# Programming C# Prog AbsBeg-00Fnt.qxd 2/22/03 6:55 PM Page ii This page intentionally left blank C# Prog AbsBeg-00Fnt.qxd 2/22/03 6:55 PM Page iii Microsoft ® C# Programming Andy Harris C# Prog AbsBeg-00Fnt.qxd 2/22/03 6:55 PM Page iv © 2002 by Premier Press. All rights reserved. No part of Publisher: this book may be reproduced or transmitted in any Stacy L. Hiquet form or by any means, electronic or mechanical, including photocopying, recording, or by any informa- Marketing Manager: tion storage or retrieval system without written per- Heather Buzzingham mission from Premier Press, except for the inclusion of brief quotations in a review. Managing Editor: Sandy Doell The Premier Press logo, top edge printing, and related trade dress is a trademark of Pre- Project Editor: mier Press, Inc. and may not be used with- Amy Pettinella out written permission. All other trademarks are the property of their respec- Editorial Assistant: tive owners. Margaret Bauer Microsoft, Windows, Internet Explorer, Notepad, Technical Reviewer: VBScript, ActiveX, and FrontPage are either registered trademarks or trademarks of Microsoft Corporation in David Talbot the United States and/or other countries. Copy Editor: All other trademarks are the property of their respec- Kate Talbot tive owners. Interior Layout: Important: Premier Press cannot provide software sup- William Hartman port. Please contact the appropriate software manufac- turer’s technical support line or Web site for assistance. Cover Design: Premier Press and the author have attempted through- Mike Tanamachi out this book to distinguish proprietary trademarks from descriptive terms by following the capitalization CD-ROM Producer: style used by the manufacturer. David Talbot Information contained in this book has been obtained Indexer: by Premier Press from sources believed to be reliable. Johnna VanHoose Dinse However, because of the possibility of human or mechanical error by our sources, Premier Press, or oth- Proofreader: ers, the Publisher does not guarantee the accuracy, ade- Lisa Neal Shaw quacy, or completeness of any information and is not responsible for any errors or omissions or the results obtained from use of such information. Readers should be particularly aware of the fact that the Internet is an ever-changing entity. Some facts may have changed since this book went to press. ISBN: 1-931841-16-0 Library of Congress Catalog Card Number: 20011098165 Printed in the United States of America 02 03 04 05 RI 10 9 8 7 6 5 4 3 2 1 C# Prog AbsBeg-00Fnt.qxd 2/22/03 6:55 PM Page v To Heather, Elizabeth, Matthew, and Jacob C# Prog AbsBeg-00Fnt.qxd 2/22/03 6:55 PM Page vi Acknowledgments T hanks first to Him from whom all life flows. Heather, you work harder at these books than I do. I appreciate your sac- rifices and your love more than ever. Thanks also to Jacob, Elizabeth, and Matthew for understanding why Daddy was typing all the time. A special thank you to everyone at Premier. This group has shown its character in the time it took to produce this book. I appreciate those I know about, and the many others whose work goes unseen. Thank you especially Stacy Hiquet for getting me started on this project, and to Amy Pettinella for her help and encouragement. Thanks to Kate Talbot for turn- ing my mush into something readable, and for laughing at my jokes before she deleted them. I can’t thank David Talbot enough for his dual role as technical editor and CD- ROM producer. His advice and insight make this a far better book than it other- wise would have been. A very special thanks to the Spring 2002, CSCI 490 class at IUPUI. You never com- plained about being guinea pigs, you worked from my very raw manuscript, and you taught me far more than I was able to teach you. C# Prog AbsBeg-00Fnt.qxd 2/22/03 6:55 PM Page vii About the Author A ndy Harrisbegan his teaching career as a high school special education teacher. During that time, he taught himself enough computing to do part-time computer consulting and database work. He began teaching computing at the university level in the late 1980s as a part-time job. Since 1995 he has been a full-time lecturer in the Computer Science Department of Indiana University/Purdue University–Indianapolis (IUPUI), where he manages the Streaming Media Lab and teaches classes in several programming languages. His primary interests are Java, Microsoft languages, Perl, JavaScript, and dynamic HTML, virtual reality, portable devices, and streaming media. This page intentionally left blank C# Prog AbsBeg-00Fnt.qxd 2/22/03 6:55 PM Page ix Contents at a Glance Introduction xxv CHAPTER 1 Basic Input and Output: A Mini Adventure 1 CHAPTER 2 Branching and Operators: The Math Game 35 CHAPTER 3 Loops and Strings: The Pig Latin Program 67 CHAPTER 4 Objects and Encapsulation: The Critter Program 99 CHAPTER 5 Constructors, Inheritance, and Polymorphism: The Snowball Fight 129 CHAPTER 6 Creating a Windows Program: The Visual Critter 165 CHAPTER 7 Timers and Animation: The Lunar Lander 211 CHAPTER 8 Arrays: The Soccer Game 253 CHAPTER 9 File Handling: The Adventure Kit 293 CHAPTER 10 Chapter Basic XML: The Quiz Maker 345 CHAPTER 11 Databases and ADO.NET: The Spy Database 397 Index 457
Description: