100% found this document useful (5 votes)
58 views

C Unleashed 1st Edition Joseph Mayo 2024 Scribd Download

Unleashed

Uploaded by

valdejusic4l
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (5 votes)
58 views

C Unleashed 1st Edition Joseph Mayo 2024 Scribd Download

Unleashed

Uploaded by

valdejusic4l
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 71

Visit https://ebookgate.

com to download the full version and


explore more ebooks

C Unleashed 1st Edition Joseph Mayo

_____ Click the link below to download _____


https://ebookgate.com/product/c-unleashed-1st-edition-
joseph-mayo/

Explore and download more ebooks at ebookgate.com


Here are some recommended products that might interest you.
You can download now and explore!

Mayo Clinic Cardiology Concise Textbook 4th Edition Joseph


G. Murphy

https://ebookgate.com/product/mayo-clinic-cardiology-concise-
textbook-4th-edition-joseph-g-murphy/

ebookgate.com

Mayo Clinic gastroenterology and hepatology board review


4ed. Edition Stephen C. Hauser

https://ebookgate.com/product/mayo-clinic-gastroenterology-and-
hepatology-board-review-4ed-edition-stephen-c-hauser/

ebookgate.com

J2EE Unleashed 1st Edition Mark Ashnault

https://ebookgate.com/product/j2ee-unleashed-1st-edition-mark-
ashnault/

ebookgate.com

The Apache 2nd Edition Joseph C. Jastrzembski

https://ebookgate.com/product/the-apache-2nd-edition-joseph-c-
jastrzembski/

ebookgate.com
Interest Groups Unleashed 1st Edition Paul S. Herrnson

https://ebookgate.com/product/interest-groups-unleashed-1st-edition-
paul-s-herrnson/

ebookgate.com

Mayo Clinic body MRI case review 1st Edition Glockner

https://ebookgate.com/product/mayo-clinic-body-mri-case-review-1st-
edition-glockner/

ebookgate.com

Microsoft Expression Blend 4 Unleashed 1st Edition Brennon


Williams

https://ebookgate.com/product/microsoft-expression-
blend-4-unleashed-1st-edition-brennon-williams/

ebookgate.com

Microsoft SharePoint 2007 Development Unleashed 1st


Edition Kevin Hoffman

https://ebookgate.com/product/microsoft-sharepoint-2007-development-
unleashed-1st-edition-kevin-hoffman/

ebookgate.com

Visual Basic 2010 Unleashed 1st Edition Alessandro Del


Sole

https://ebookgate.com/product/visual-basic-2010-unleashed-1st-edition-
alessandro-del-sole/

ebookgate.com
C#
Joseph Mayo

Unleashed
PUBLISHER
C# Unleashed Paul Boger
Copyright © 2002 by Sams Publishing
EXECUTIVE EDITOR
All rights reserved. No part of this book shall be reproduced, stored in a
Shelley Kronzek
retrieval system, or transmitted by any means, electronic, mechanical, photo-
copying, recording, or otherwise, without written permission from the publish- DEVELOPMENT EDITOR
er. No patent liability is assumed with respect to the use of the information Susan Hobbs
contained herein. Although every precaution has been taken in the preparation
MANAGING EDITOR
of this book, the publisher and author assume no responsibility for errors or
Charlotte Clapp
omissions. Nor is any liability assumed for damages resulting from the use of
the information contained herein. PROJECT EDITORS
International Standard Book Number: 0-672-32122-x Elizabeth Finney
Leah Kirkpatrick
Library of Congress Catalog Card Number: 00-111066
COPY EDITOR
Printed in the United States of America
Maryann Steinhart
First Printing: November 2001
INDEXER
04 03 02 01 4 3 2 1 D&G Limited, LLC

Trademarks PROOFREADER
D&G Limited, LLC
All terms mentioned in this book that are known to be trademarks or service
marks have been appropriately capitalized. Sams Publishing cannot attest to TECHNICAL EDITORS
the accuracy of this information. Use of a term in this book should not be Kevin Burton
regarded as affecting the validity of any trademark or service mark. Bill Craun

TEAM COORDINATOR
Warning and Disclaimer Pamalee Nelson
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 MEDIA DEVELOPER
an “as is” basis. The author and the publisher shall have neither liability nor Dan Scherf
responsibility to any person or entity with respect to any loss or damages aris- INTERIOR DESIGNER
ing from the information contained in this book or from the use of programs Gary Adair
accompanying it.
COVER DESIGNER
Aren Howell

PAGE LAYOUT
D&G Limited, LLC
Contents at a Glance
Introduction 1

PART I C# Basics 9
1 The C# Environment 11
2 Getting Started with C# 19
3 Writing C# Expressions 47
4 Using Statements and Loops to Control Program Flow 69
5 Debugging and Pre-Processing 91

Part II Object and Component Programming with C# 107


6 Object and Component Concepts 109
7 Working with Classes 129
8 Designing Object-Oriented Programs 177
9 Overloading Class Members and Operators 219
10 Handling Exceptions and Errors 237
11 Delegates and Events 255
12 Organizing Code with Namespaces 277
13 Creating structs 289
14 Implementing Interfaces 301
15 Performing Conversions 329

Part III Using Class Libraries with C# 341


16 Presenting Graphical User Interfaces 343
17 File I/O and Serialization 381
18 XML 407
19 Database Programming with ADO.NET 417
20 Writing Web Applications with ASP.NET 439
21 Remoting 459
22 Web Services 483
Part IV Extreme C# 495
23 Multi-Threading 497
24 Browsing the Network Libraries 503
25 String Manipulation 515
26 C# Collections 545
27 Attributes 567
28 Reflection 581
29 Localization and Resources 595
30 Unsafe Code and PInvoke 619
31 Runtime Debugging 635
32 Performance Monitoring 647
33 Integrating C# with COM 679

Part V The C# Environment 693


34 Garbage Collection 695
35 Cross-Language Programming with C# 711
36 The Common Language Runtime 725
37 Versioning and Assemblies 733
38 Securing Code 745

Part VI Appendixes 759


A Compiling Programs 761
B The .NET Frameworks Class Library 767
C Online Resources 773

Index 775
Contents
Introduction 1

Part I C# Basics 9
1 The C# Environment 11
The Common Language Infrastructure (CLI) ......................................12
Standardization ....................................................................................15
The .NET Architecture ........................................................................16
Common Language Runtime (CLR) ..............................................16
Libraries ..........................................................................................16
Languages ........................................................................................17
Where C# Fits In ..................................................................................17
Summary ..............................................................................................17

2 Getting Started with C# 19


Writing a Simple C# Program ..............................................................20
Comments ............................................................................................22
Multi-Line Comments ....................................................................22
Single-Line Comments ....................................................................23
XML Documentation Comments ....................................................23
Identifiers and Keywords ......................................................................24
Identifiers ........................................................................................24
Keywords ........................................................................................26
Style ......................................................................................................26
Preparing a Program To Run ................................................................27
Basic C# Types ....................................................................................28
Variable Declarations ......................................................................29
The Simple Types ............................................................................29
Struct Types ....................................................................................34
Reference Types ..............................................................................34
Enumeration Types ..........................................................................35
String Type ......................................................................................36
C#
vi
UNLEASHED

Definite Assignment ............................................................................37


Basic Conversions ................................................................................38
Arrays ....................................................................................................40
Single-dimension Arrays ................................................................40
N-Dimensional Arrays ....................................................................42
Jagged Arrays ..................................................................................42
Interacting with Programs ....................................................................43
Summary ..............................................................................................46

3 Writing C# Expressions 47
Unary Operators ....................................................................................48
The Plus Operator ............................................................................48
The Minus Operator ........................................................................49
The Increment Operator ..................................................................49
The Decrement Operator ................................................................50
The Logical Complement Operator ................................................50
The Bitwise Complement Operator ................................................50
Binary Operators ..................................................................................51
Arithmetic Operators ......................................................................51
Relational Operators ........................................................................53
Logical Operators ............................................................................55
Assignment Operators ....................................................................58
The Ternary Operator ..........................................................................59
Other Operators ....................................................................................60
The is Operator ..............................................................................60
The as Operator ..............................................................................60
The sizeof() Operator ..................................................................60
The typeof() Operator ..................................................................60
The checked() Operator ..................................................................61
The unchecked() Operator ..............................................................61
Enumeration Expressions ....................................................................61
Array Expressions ................................................................................63
Statements ............................................................................................65
Blocks ..................................................................................................65
Labels ....................................................................................................66
Declarations ..........................................................................................66
Operator Precedence and Associativity ................................................66
Summary ..............................................................................................68

4 Using Statements and Loops to Control Program Flow 69


if Statements ........................................................................................70
Simple if ........................................................................................70
if-then-else ..................................................................................71
if-else if-else ............................................................................71
vii
CONTENTS

switch Statements ................................................................................73


C# Loops ..............................................................................................76
while Loops ....................................................................................77
do Loops ..........................................................................................78
for Loops ........................................................................................79
foreach Loops ................................................................................80
goto Statements ....................................................................................81
break Statements ..................................................................................83
continue Statements ............................................................................84
return Statements ................................................................................84
Summary ..............................................................................................88

5 Debugging and Pre-Processing 91


Pre-Processing Directives ....................................................................92
Define Directive ..............................................................................92
Conditionals ....................................................................................92
Errors ..............................................................................................93
Line Numbers ..................................................................................94
Comments ........................................................................................94
Debugging C# Programs ......................................................................94
The Debugging Approach ..............................................................95
Using the Debugger To Find a Program Error ................................96
Attaching to Processes ..................................................................101
Summary ............................................................................................106

Part II Object and Component Programming with C# 107


6 Object and Component Concepts 109
What Is an Object? ............................................................................110
Object Classification ..........................................................................112
Object Hierarchies ..............................................................................113
Abstraction ..........................................................................................114
Objects within Objects ........................................................................115
Objects with Different Behaviors ......................................................116
Component Interfaces ........................................................................120
Component Properties ........................................................................123
Component Events ..............................................................................125
Summary ............................................................................................128

7 Working with Classes 129


Class Members ....................................................................................130
Instance and Static Members ..............................................................131
Use of Accessibility Modifiers ..........................................................131
Fields ..................................................................................................132
C#
viii
UNLEASHED

Field Initialization ........................................................................132


Definite Assignment ......................................................................133
Constant Fields ..............................................................................134
readonly Fields ............................................................................135
XML Comments ............................................................................135
Constructors ........................................................................................135
Instance Constructors ....................................................................136
Static Constructors ........................................................................141
Destructors ..........................................................................................142
Methods ..............................................................................................143
Instance Methods ..........................................................................144
Method Signature ..........................................................................144
Method Body ................................................................................147
Local Fields ..................................................................................147
Method Parameters ........................................................................148
Static Methods ..............................................................................155
XML Comments ............................................................................156
Properties ............................................................................................156
Property Accessors ........................................................................157
Transparent Access ........................................................................159
Static Properties ............................................................................160
Late Bound Object Creation ..........................................................161
XML Comments ............................................................................162
Indexers ..............................................................................................162
XML Comments ............................................................................164
Full XML Comments ..........................................................................165
Summary ............................................................................................176

8 Designing Object-Oriented Programs 177


Inheritance ..........................................................................................178
Base Classes ..................................................................................178
Abstract Classes ............................................................................180
Calling Base Class Members ........................................................188
Hiding Base Class Members ........................................................191
Versioning ......................................................................................193
Sealed Classes ..............................................................................197
Encapsulating Object Internals ..........................................................198
Data Hiding ..................................................................................198
Modifiers Supporting Encapsulation ............................................199
Other Encapsulation Strategies ....................................................199
Relationship of Encapsulation to Inheritance ..............................200
ix
CONTENTS

Polymorphism ....................................................................................200
Implementing Polymorphism ........................................................201
Hiding Again ................................................................................206
Most-Derived Implementations ....................................................210
Polymorphic Properties ................................................................213
Polymorphic Indexers ....................................................................215
Summary ............................................................................................217

9 Overloading Class Members and Operators 219


Overloading Methods ........................................................................220
Overloading Indexers ..........................................................................223
Overloading Operators ........................................................................227
Resolving Overloaded Members ........................................................234
Summary ............................................................................................235

10 Handling Exceptions and Errors 237


try/catch Blocks ..............................................................................238
finally Blocks ..................................................................................240
Predefined Exception Classes ............................................................241
Handling Exceptions ..........................................................................241
Handling Multiple Exceptions ......................................................242
Handling and Passing Exceptions ................................................243
Recovering from Exceptions ........................................................246
Designing Your Own Exceptions ........................................................249
checked and unchecked Statements ....................................................251
Summary ............................................................................................253

11 Delegates and Events 255


Delegates ............................................................................................256
Defining Delegates ........................................................................256
Creating Delegate Method Handlers ............................................257
Hooking Up Delegates and Handlers ............................................257
Invoking Methods through Delegates ..........................................258
Multi-Cast Delegates ....................................................................258
Delegate Equality ..........................................................................261
Events ..................................................................................................262
Defining Event Handlers ..............................................................262
Registering for Events ..................................................................264
Implementing Events ....................................................................265
Firing Events ................................................................................267
Modifying Event Add/Remove Methods ......................................269
Summary ............................................................................................275
C#
x
UNLEASHED

12 Organizing Code with Namespaces 277


Why Namespaces? ..............................................................................278
Organizing Code ............................................................................278
Avoiding Conflict ..........................................................................279
Namespace Directives ........................................................................280
The using Directive ......................................................................280
The alias Directive ......................................................................281
Creating Namespaces ..........................................................................282
Namespace Members ..........................................................................286
Scope and Visibility ............................................................................286
Summary ............................................................................................288

13 Creating structs 289


Identifying the class/struct Relationship ........................................290
Value Versus Reference ................................................................291
Inheritance ....................................................................................292
Other Differences ..........................................................................293
Trade-Offs ......................................................................................293
Type System Unification ....................................................................294
The Pre-Defined Types as structs ..............................................294
Boxing and Unboxing ..................................................................295
Designing a New Value Type ..............................................................295
Summary ............................................................................................298

14 Implementing Interfaces 301


Abstract Class Versus Interface ..........................................................302
Interface Members ..............................................................................302
Methods ........................................................................................303
Properties ......................................................................................303
Indexers ........................................................................................304
Events ............................................................................................304
Implicit Implementation ....................................................................304
Single Class Interface Implementation ........................................305
Simulating Polymorphic Behavior ................................................309
Explicit Implementation ....................................................................315
Mapping ..............................................................................................321
Inheritance ..........................................................................................324
Summary ............................................................................................327

15 Performing Conversions 329


Implicit Versus Explicit Conversions ..................................................330
Value Type Conversions ....................................................................335
Reference Type Conversions ..............................................................338
Summary ............................................................................................339
xi
CONTENTS

Part III Using Class Libraries with C# 341


16 Presenting Graphical User Interfaces 343
Windows ............................................................................................344
Controls ..............................................................................................348
N-Tier Architecture ............................................................................351
Menus ..................................................................................................373
Summary ............................................................................................379

17 File I/O and Serialization 381


Files and Directories ..........................................................................382
Streams ................................................................................................391
Reading and Writing with Streams ..............................................391
Implementing a Cryptographic Stream ........................................395
Serialization ........................................................................................398
Automatic Serialization ................................................................398
Custom Serialization ....................................................................401
Summary ............................................................................................406

18 XML 407
Writing ................................................................................................408
Reading ..............................................................................................411
Summary ............................................................................................416

19 Database Programming with ADO.NET 417


Making Connections ..........................................................................418
Viewing Data ......................................................................................420
Manipulating Data ..............................................................................425
Calling Stored Procedures ..................................................................429
Retrieving DataSets ............................................................................435
Summary ............................................................................................438

20 Writing Web Applications with ASP.NET 439


A Simple Web Page ............................................................................440
Controls ..............................................................................................441
Server Controls ..............................................................................441
HTML Controls ............................................................................442
Validation Controls ........................................................................443
Making a Web Form ..........................................................................443
A Simple Web Form ......................................................................444
Manipulating Web Form Controls ................................................448
Code-Behind Web Pages ....................................................................452
Summary ............................................................................................457
C#
xii
UNLEASHED

21 Remoting 459
Basic Remoting ..................................................................................460
Remoting Server ............................................................................461
Remoting Client ............................................................................463
Remoting Setup ............................................................................465
Proxys ................................................................................................471
Channels ..............................................................................................475
Lifetime Management ........................................................................478
Summary ............................................................................................481

22 Web Services 483


Web Service Basics ............................................................................484
Web Service Technologies ............................................................484
A Basic Web Service ....................................................................485
Viewing Web Service Info ............................................................486
Using Web Services ............................................................................490
Summary ............................................................................................493

Part IV Extreme C# 495


23 Multi-Threading 497
Creating New Threads ........................................................................498
Synchronization ..................................................................................499
Summary ............................................................................................502

24 Browsing the Network Libraries 503


Implementing Sockets ........................................................................504
A Socket Server ............................................................................504
A Socket Client ............................................................................507
Compiling and Running Server and Client ..................................511
Working with HTTP ..........................................................................512
Summary ............................................................................................514

25 String Manipulation 515


The String Class ................................................................................516
static Methods ................................................................................517
Instance Methods ..........................................................................522
Properties and Indexers ................................................................532
The StringBuilder Class ..................................................................533
Instance Methods ..........................................................................533
Properties and Indexers ................................................................538
String Formatting ..............................................................................540
Numeric Formatting ......................................................................540
Picture Formatting ........................................................................541
xiii
CONTENTS

Regular Expressions ..........................................................................541


Summary ............................................................................................543

26 C# Collections 545
Pre-Existing Collections ....................................................................546
The ArrayList Collection ............................................................546
The BitArray Collection ..............................................................547
The Hashtable Collection ............................................................549
The Queue Collection ....................................................................549
The SortedList Collection ..........................................................550
The Stack Collection ....................................................................551
Collection Interfaces ..........................................................................552
Creating a Collection ..........................................................................553
A List Collection ..........................................................................553
Using the SiteList Collection ......................................................563
Summary ............................................................................................565

27 Attributes 567
Using Attributes ..................................................................................568
Using a Single Attribute ................................................................568
Using Multiple Attributes ..............................................................569
Using Attribute Parameters ................................................................570
Positional Parameters ....................................................................571
Named Parameters ........................................................................571
Using Attribute Targets ......................................................................572
Creating Your Own Attributes ............................................................574
The AttributeUsage Attribute ......................................................574
Getting Attributes from a Class ..........................................................578
Summary ............................................................................................579

28 Reflection 581
Discovering Program Information ......................................................582
Dynamically Activating Code ............................................................588
Reflection.Emit ................................................................................590
Summary ............................................................................................594

29 Localization and Resources 595


Resource Files ....................................................................................596
Creating a Resource File ..............................................................596
Writing a Resource File ................................................................599
Reading a Resource File ................................................................600
Converting a Resource File ..........................................................601
Creating Graphical Resources ......................................................603
C#
xiv
UNLEASHED

Multiple Locales ................................................................................609


Implementing Multiple Locales ....................................................610
Finding Resources ........................................................................616
Summary ............................................................................................617

30 Unsafe Code and PInvoke 619


Unsafe Code ........................................................................................620
What Do You Mean My Code Is Unsafe? ....................................620
The Power of Pointers ..................................................................621
The sizeof() Operator ................................................................625
The stackalloc Operator ..............................................................626
The fixed Statement ....................................................................628
Platform Invoke ..................................................................................631
Summary ............................................................................................633

31 Runtime Debugging 635


Simple Debugging ..............................................................................636
Conditional Debugging ......................................................................638
Runtime Tracing ................................................................................641
Making Assertions ..............................................................................643
Summary ............................................................................................644

32 Performance Monitoring 647


Accessing Built-in Performance Counters ........................................648
Implementing Timers ..........................................................................656
Building a Customized Performance Counter ....................................657
Analyzing Performance with Sampling ..............................................668
Summary ............................................................................................677

33 Integrating C# with COM 679


Communicating with COM from .NET ............................................680
Early-Bound COM Component Calls ..........................................680
Late-Bound COM Component Calls ............................................682
Exposing a .NET Component as a COM Component ......................683
Introduction to .NET Support for COM+ Services ............................685
Transactions ..................................................................................687
JIT Activation ................................................................................688
Object Pooling ..............................................................................689
Other Services ..............................................................................690
Summary ............................................................................................690
xv
CONTENTS

Part V The C# Environment 693


34 Garbage Collection 695
Automatic Memory Management ......................................................696
Inside the Garbage Collector ........................................................697
Garbage Collector Optimization ..................................................698
Finalizing Your Code Properly ..........................................................699
The Problems with Destructors ....................................................699
The Dispose Pattern ......................................................................700
The using Statement ....................................................................701
Controlling Garbage Collection ..........................................................703
Controlling Objects ......................................................................703
Weak References ..........................................................................705
Summary ............................................................................................709

35 Cross-Language Programming with C# 711


The Common Type System (CTS) ....................................................712
The Common Language Specification (CLS) ....................................713
Tips for Making Your Code CLS-Compatible ....................................713
General ..........................................................................................714
Naming ..........................................................................................715
Types ..............................................................................................715
Methods ........................................................................................716
Indexers and Properties ................................................................717
Events ............................................................................................717
Pointers ..........................................................................................718
Interfaces ......................................................................................718
Inheritance ....................................................................................718
Arrays ............................................................................................719
Enums ............................................................................................719
Attributes ......................................................................................720
Assemblies ....................................................................................720
Writing a Cross-Language Program ..................................................721
Summary ............................................................................................724

36 The Common Language Runtime 725


Managed Execution ............................................................................726
Creating Source Code ....................................................................727
Compiling to Intermediate Code ..................................................727
Compiling to Native Code ............................................................727
Executing the Program ..................................................................728
Metadata ..............................................................................................728
Uses of Metadata ..........................................................................729
C#
xvi
UNLEASHED

Managed Services ..............................................................................729


Exception Handling ......................................................................729
Automatic Lifetime Management ................................................730
Interoperability ..............................................................................730
Security ..........................................................................................730
Profiling and Debugging ..............................................................730
Summary ............................................................................................730

37 Versioning and Assemblies 733


Inside Assemblies ..............................................................................734
Manifests ......................................................................................735
Attributes ......................................................................................735
Assembly Features ..............................................................................738
Identity ..........................................................................................738
Scope ............................................................................................738
Versioning ......................................................................................738
Security ..........................................................................................739
Configuration ......................................................................................740
Startup Configuration ....................................................................741
Runtime Configuration ..................................................................741
Deployment ........................................................................................743
Summary ............................................................................................744
38 Securing Code 745
Code-Based Security ..........................................................................746
Evidence ........................................................................................746
Permissions ....................................................................................747
Code Groups ..................................................................................747
Security Policy Levels ..................................................................749
Permission Requests ......................................................................750
Implementing Security Policy ......................................................753
Role-Based Security ..........................................................................755
Security Utilities ................................................................................757
Summary ............................................................................................758

Part VI Appendixes 759


A Compiling Programs 761
Assemblies ..........................................................................................762
Debug ..................................................................................................762
Miscellaneous ....................................................................................763
Optimization ......................................................................................764
Output ................................................................................................764
Preprocessing ......................................................................................765
Resources ............................................................................................765

B The .NET Frameworks Class Libraries 767

C Online Resources 773


C# Sites ..............................................................................................774
.NET Sites ..........................................................................................774

Index 775
About the Author
Joe Mayo is a pioneer within the C# community. Joe created the C# Station Web site
shortly after this new language was introduced. His very popular C# Tutorials are
accessed by Web developers and Web sites throughout the world. Joe is a seasoned
developer with more than 15 years of robust experience. Over the years, he has pro-
grammed in a variety of languages including assembler, C, C++, VBA, and Forte 4GL.
His database experience encompasses Paradox, Dbase III, MS Access, and Oracle.
Frameworks include MFC and Motif. He has programmed several operating systems
including VAX VMS, RSX-11, UNIX, and several versions of MS-DOS and MS
Windows. He has developed applications in standalone mode for desktops, client-server
on LANs, and n-tier applications on LANs and WANs. Joe opened a Web site titled C#
Station in late June 2000. He is currently a software engineer for Quest
Communications.
Dedication
To my beautiful wife, Maytinee

You are the vision, the light


guiding my way

Your strength and support


enable perseverance

Mother of our children and best friend


I love and thank you dearly

—Joe Mayo
Acknowledgments
Although my name appears on the cover of this book, work of such magnitude could
never have occurred without the valuable contributions of many people. To the people at
Sams Publishing, Microsoft, and friends and family I am eternally grateful.
I’d first like to thank Shelley Kronzek, Executive Editor, for finding me and offering this
wonderful opportunity. Her leadership is inspiring. Susan Hobbs, Development Editor,
was totally awesome, keeping me on focus and organized. Maryann Steinhart, Copy
Editor, made my writing look great. Other people at Sams Publishing I’d like to recog-
nize include Katie Robinson, Leah Kirkpatrick, Elizabeth Finney, Pamalee Nelson, and
Laurie McGuire. Thanks also to all the editors, indexers, printers, production, and other
people at Sams who have contributed to this book.
Special thanks goes to Kevin Burton and Bill Craun, technical editors. Their technical
expertise and advice was absolutely top-notch. They provided detailed pointers, and their
perspectives made a significant difference. Thanks to Keith Olsen, Charles Tonklinson,
Cedric, and Christoph Wille for reviewing my early work.
Thanks to all the people at Microsoft who set up author seminars and training. They are
transforming the way we do computing and leading the industry in a move of historic
proportions—an initiative deserving of much praise. Special thanks to Eric Gunnerson
for taking time out of his extremely busy schedule to review my chapters.
This first book is a significant milestone in my life. As such, I must recognize those peo-
ple who contributed to my success. In many ways, they define who I am.
Thanks to family members: Maytinee Mayo, Joseph A. Mayo Jr., Jennifer A. Mayo,
Kamonchon Ahantric, Lacee and June Mayo, Bob Mayo, Margina Mayo, Richard Mayo,
Gary Mayo, Mike Mayo, Tony Gravagno, Tim and Kirby Hoffman, Richard and Barbara
Bickerstaff, Bobbie Jo Burns, David Burns, Mistie Lea Bickerstaff, Cecil Sr. and
Margaret Sloan, Cecil Jr. and Jean Sloan, Lou and Rose Weiner, Mary and Ron Monette,
Jack Freeman Sr., and Bill Freeman.
Thanks to friends and professional associates: Evelyn Black, Harry G. Hall, Arthur E.
Richardson, Carl S. Markussen, Judson Meyer, Hoover McCoy, Bill Morris, Gary Meyer,
Tim Leuers, Angela Dees-Prebula, Bob Jangraw, Jean-Paul Massart, Jeff and Stephanie
Manners, Eddie Alicea, Gary and Gloria Lefebvre, Bob Turbyfill, and Dick Van
Bennekom, Barry Patterson, Otis Solomon, and Brian Allen.
Tell Us What You Think!
As the reader of this book, you are our most important critic and commentator. We value
your opinion and want to know what we’re doing right, what we could do better, what
areas you’d like to see us publish in, and any other words of wisdom you’re willing to
pass our way.
As an Executive Editor for Sams, I welcome your comments. You can e-mail or
write me directly to let me know what you did or didn’t like about this book—as well as
what we can do to make our books stronger.
Please note that I cannot help you with technical problems related to the topic of this
book, and that due to the high volume of mail I receive, I might not be able to reply to
every message.
When you write, please be sure to include this book’s title and author as well as your
name and phone or fax number. I will carefully review your comments and share them
with the author and editors who worked on the book.

Email: feedback@samspublishing.com
Mail: Mark Taber
Executive Editor
Sams Publishing
800 East 96th Street
Indianapolis, IN 46240 USA
Introduction
Welcome to C# Unleashed, a programmer’s guide and reference to the C# (pronounced
“see sharp”) programming language. C# is a brand-new object-oriented programming
(OOP) language that emphasizes a component-based approach to software development.
While component-based programming has been with us, in one form or another, for a
few years now, the vision of what C# enables promises to take us to the next level in
software development. This is the new paradigm shift toward XML Web Services—the
view of software as a service, disconnected, stateless, and conforming to international
open standards.
Software as a service is the vision of the next generation of computing systems. For
example, C# is well suited for building Web services, reusable components on the
Internet that conform to open standards. Software development is no longer constrained
to the monolithic architectures we have been developing over the last several years. Web
services enable applications to use distributed services over the Web, which simplify
development and promote a greater scale of software reuse. C# is a major player in the
Web services arena, promoting the vision of software as a service.
This book not only teaches the C# language itself, but its goal is to show how C# could
be used to develop software as a service. Looking at the evolution of software, it’s evi-
dent how we’ve reached this point in time. For many years, programs were written as
monolithic applications with a single purpose. Through research and experience, we
realized the benefits of modularization, which eventually led to object-oriented methods.
This gave us large-scale re-use and maintainability. Client/server and networking tech-
nology evolved naturally as collaboration and communication became business require-
ments. Enter the Internet and Web technology, providing distributed, stateless, and secure
software technologies, including applets and other Web page objects. The next evolution-
ary step is where C# fits in: automating the Internet.

Why This Book Is for You


If you’ve developed software in any other computer programming language, you will be
able to understand the contents of this book with no trouble. You already know how to
make logical decisions and construct iterative code. You also understand variables and
basic number systems like hexadecimal. Honestly, ambitious beginners could do well
with this book if they’re motivated.
Having developed software for several years, I stepped back into some old shoes many
times during writing this book. A common question I’d ask myself was, “What if I just
C#
2
UNLEASHED

spent the last two years programming Y2K fixes in COBOL?” or “What if I was a PRO-
LOG programmer doing scientific research for a number of years?” Would someone
working with language X understand a certain explanation or example? When the answer
was positive, I felt confident that I had given you fair consideration.
This is a book written for every programmer. Although it has notes for a couple of the
larger potential groups of readers, C++ and Java programmers, it considers all program-
mers. It’s basic enough for you to see every aspect of C# that’s possible, yet it’s suffi-
ciently advanced to provide insight into the modern enterprise-level tasks you deal with
every day. I hope this book leaves you with a sense that you now have a valuable new
tool in your backpack to develop the Web services and distributed solutions that are ulti-
mately our destiny.

Organization and Goals


C# Unleashed is all about writing code in the C# programming language. Many of the
advanced topics could fill books of their own, but the primary focus is not to teach the
details of the advanced topics, although some areas do have significant depth. The goal
within each of the chapters is to show how C# is used to perform a given task. Even in
the more theoretical chapters, the focus is on how each topic applies to writing code
in C#.
This book is divided into six major parts. It begins with the simpler material and those
items strictly related to the C# language itself. Later, the book moves into C#-related
areas, showing how to use libraries. Then it covers more advanced topics, showing how
to develop code for various technologies using C#.

Part I: C# Basics
Part I provides the most basic elements of C# language syntax. It begins by introducing
the environment C# operates in and then showing how to create a couple simple C# pro-
grams. The different C# types and how they’re used to create expressions and statements
are covered. There is a chapter on controlling program flow with branching and iteration.
After enough material has been covered so that the reader understands a moderately
sophisticated program, there is a chapter on how to debug C# programs.
• Chapter 1 C# does not operate in a typical environment where programs are
compiled directly to machine code. It runs in a virtual execution system that man-
ages how the code runs. There are several technologies that enable this environ-
ment to operate the way it does. C# is also being submitted as an open standard.
The material is purposely brief, so you can quickly dive into the main purpose of
the book, writing C# code.
3
INTRODUCTION

• Chapter 2 The basics of C# include how to build a simple program, basic syn-
tax, and information on C# types. C# syntax and types are much like those of its C
and C++ parent languages.
• Chapter 3 Central to computing in any language is the ability to manipulate data
with expressions. C# includes an entire suite of unary, binary, and ternary expres-
sions. Highlights include forming expressions, operator precedence, and working
with enum and array types.
• Chapter 4 Rounding out basics of the C# language are several constructs allow-
ing control of program flow. Besides the traditional if and select statements and
while and for loops, there is an explanation of the new foreach loop. I even touch
upon the infamous goto statement.
• Chapter 5 Advanced programmers, please bear with me. I sincerely believe
that debugging is so important, especially to intermediate programmers, that
there is an entire chapter dedicated to it. There is also an introductory section on
pre-processing directives.

Part II: Object and Component Programming


with C#
Part II covers object and component programming in C#. For some, this is one of the
toughest things to learn, so I start at a very basic level and then go into more depth. In
fact, there is a set of three entire chapters dedicated exclusively to object and component
programming concepts. The rest of the chapters in this part deal with other types of C#
objects and how to use the object-oriented features of C#.
• Chapter 6 A large part of programming with C# is understanding object-
oriented programming (OOP). If you’re an OOP purist, count to 10. This is a
chapter focused on programmers coming from functional, logical, or procedural
paradigms. Many people learning OOP will scratch their heads for a while before
they get the “Ah-ha!” experience. This material is designed to help “Ah-ha!” come
a little more quickly.
• Chapter 7 One of the most used objects in C# is the class. This chapter’s focus
is on the mechanics of creating a class and its members, including constructors,
destructors, fields, methods, properties, and indexers. There is also an entire pro-
gram demonstrating how XML comments are used.
• Chapter 8 Classes define objects that, in turn, have object-oriented behavior.
Discussion and examples drill down into how object-oriented programming is per-
formed with classes.
C#
4
UNLEASHED

• Chapter 9 Method and operator overloading in C# is similar to C and C++ but


has nuances that make it unique. There are several examples that explain how to
overload members and operators and show some of the new constraints and safe-
guards.
• Chapter 10 C# has extensive error handling and exception support. Pertinent
items discussed include exception handling with try/catch/finally blocks, excep-
tion creation and management, and exception recovery.
• Chapter 11 Events and delegates are closely related and provide support for
late-bound method invocation. This chapter presents the delegate object first and
then shows how it is used with the event class member.
• Chapter 12 Namespaces were briefly introduced earlier in the book, but now
they are discussed in detail, including namespace declaration and how to use
namespaces to organize code and avoid identifier naming conflicts.
• Chapter 13 A struct is another C# object type. It’s similar to a class in mechan-
ics but possesses different semantics. Since a struct contains many of the same
members as a class, this chapter focuses on the unique features of a struct and its
difference from the class type.
• Chapter 14 Interface-based programming is superior in exposing the public con-
tract an object exposes to potential clients. This chapter presents thorough and
detailed information on how to implement interfaces in a C# program.
• Chapter 15 C# is a very strongly typed language. The discussion focuses on
how to maintain type safety, while still being able to make conversions between
user-defined types.

Part III: Using Class Libraries with C#


Part III introduces several of the class libraries available to C#.
• Chapter 16 Although the new vision is Web services, there is still a large audi-
ence for desktop graphical user interface (GUI) applications. The Windows Forms
library is presented with emphasis on showing how to create a simple user inter-
face with Windows Forms controls.
• Chapter 17 An entire chapter is devoted to file input/output (I/O), explaining
how C# is used to write to and read from files. There is also a discussion about
streams.
• Chapter 18 XML is integrated thoroughly with the base class libraries, underly-
ing its importance in future applications. Examples concentrate on using existing
libraries with C# to manipulate XML data.
5
INTRODUCTION

• Chapter 19 The primary means of programming databases with C# is through


ADO.NET. The examples show how to use many of the ADO.NET classes for tra-
ditional and Web-based database access.
• Chapter 20 The discussion of ASP.NET brings Web software development into
focus. ASP.NET Web pages can be developed with code written in C#. Examples
include how to program controls and Web programs with C# code.
• Chapter 21 Remoting is an extensible distributed object programming technol-
ogy. C# is excellently suited for developing programs using remoting technology.
This chapter not only shows how to program remote objects, but also how to
employ the technology’s extensibility features.
• Chapter 22 Building Web services with C# is extremely easy. Examples use the
existing ASP.NET infrastructure and .NET utilities to show how simple it is to
develop a Web service.

Part IV: Extreme C#


Part IV gives those advanced topics for extreme performance and enterprise program-
ming projects.
• Chapter 23 Modern programming languages support multithreading and so does
C#. This chapter includes examples of how to create a multithreaded program and
how to implement thread synchronization.
• Chapter 24 The base class library includes classes supporting Internet communi-
cations. This chapter presents methods of communicating via TCP/IP sockets as
well as how to use classes that implement the HTTP protocol. There are examples
of HTTP Web and SMTP e-mail programming.
• Chapter 25 Much of the information manipulation performed in programming
deals with text data. This entire chapter is dedicated to string manipulation with
C#, including the String and StringBuilder classes, string formatting, and
regular expressions.
• Chapter 26 When the array type isn’t enough for an application’s data structure
requirements, there are collections. Examples show how to use several collections
in the base class library as well as how to create a custom collection with code
implementing the required interfaces.
• Chapter 27 Attributes are the part of the C# language that allow you to add
declarative functionality to a program. Attribute usage is explained, as well as how
to create custom attributes.
C#
6
UNLEASHED

• Chapter 28 C# has a capability called reflection that enables a program to exam-


ine information about itself. The examples show how to perform reflection as well
as how to dynamically build programs that can be run from memory or saved to an
executable file.
• Chapter 29 Localization is the process of making a program present information
for different cultures. There are examples of how to localize programs for multiple
cultures.
• Chapter 30 In practical terms, there will be many projects that want to reuse
existing native libraries, interact with operating system code, and perform low-
level operations. This chapter shows how to accomplish these things in C#.
• Chapter 31 Complex systems need mechanisms to detect runtime problems.
Examples in this chapter show how to perform runtime debugging and tracing with
pertinent elements of the base class libraries.
• Chapter 32 Another important runtime task is the ability to capture application
performance data. Performance counters are used to gather statistics, which help in
analyzing how an application performs at runtime under specified conditions.
• Chapter 33 There are a lot of COM and COM+ programmers out there.
Programs in this chapter show how to call COM from C# and how to call C# from
COM. The base class libraries include enterprise service classes enabling C# pro-
grams to use COM+ services. Examples show how to perform tasks using COM+
services such as transactions, object pooling, and others.

Part V: The C# Environment


Part V goes into depth on the C# environment.
• Chapter 34 Memory for C# programs is managed by a high-performance
garbage collector. Discussions illustrate how the garbage collector works and why
it’s efficient. There are examples that demonstrate how to interact with the garbage
collector and different ways to work with objects to help control their clean-up.
• Chapter 35 The environment C# operates in supports cross-language program-
ming. There are examples of how to create code in different languages and compile
them into the same program. The section on the Common Language Specification
(CLS) illuminates the specific areas of the CLS that affect C# programs.
• Chapter 36 To understand how C# programs run and the meaning of managed
code, you must have an understanding of the theory behind the CLR. Much of the
information has already been described as a natural part of other C# language ele-
ments, but this material enhances and solidifies what is known.
7
INTRODUCTION

• Chapter 37 C# programs are deployed as assemblies, so it’s important to under-


stand what assemblies are and how to work with them. This chapter shows what
assemblies are made of and covers the various attributes that define them.
• Chapter 38 The book wraps up with security. The material covers the elements
of code-based security and how they interact to protect a system from code. Other
sections show how to implement code-based and role-based security with both
code and attributes.

Part VI: Appendixes


Part VI consists of supplementary material on compiling programs, an overview of .NET
Class Library components, and some other resources that may be of interest.
• Appendix A Examples of various compiler options are provided in this
appendix.
• Appendix B This appendix provides an overview of the .NET libraries.
• Appendix C This index of selected C# and .NET Web sites is helpful.
C# Basics
PART
I
IN THIS PART
1 The C# Environment 11

2 Getting Started with C# 19

3 Writing C# Expressions 47

4 Using Statements and Loops to Control Program


Flow 69

5 De-Bugging and Pre-Processing 91


The C#
CHAPTER 1 Environment

IN THIS CHAPTER
• The Common Language Infrastructure
(CLI) 12
• Standardization 15

• The .NET Architecture 16

• Where C# Fits In 17
C# Basics
12
PART I

This chapter provides an overview of the environment in which C# operates. This is


important for a couple reasons. While learning C#, a familiar question may reappear as
to what functionality belongs to the libraries and what capabilities are built into the lan-
guage. This question is addressed in this chapter to help evaluate what capabilities are
available to meet requirements.
Another good reason to understand the C# environment relates to standardization.
There will be a need for some software engineers to develop cross-platform appli-
cations. With a good understanding of what elements of an environment contribute
to a standard installation, cross-platform development can proceed in a much smoother
fashion.

The Common Language


Infrastructure (CLI)
The primary purpose of the Common Language Infrastructure (CLI) is to facilitate
the creation and execution of distributed components and services. It accomplishes
this by enabling programs written in different languages to operate together, giving
programs the capability to describe themselves, and providing the execution environ-
ment to support multiple platforms. The CLI is composed of the following four major
sections:
• Common Type System (CTS)
• Common Language Specification (CLS)
• Metadata
• Virtual Execution System (VES)
The CTS was designed to support common data types from a wide variety of program-
ming languages. This opens the door for many languages to join the CLI. In addition, the
CTS supports concepts such as type safety, which produces more robust programs and
better security.
The CLS is a sub-specification of the CTS. Its purpose is to enhance the communication
between programs written in other languages. When a program or class declares it is
CLS-compliant, that means it can be reliably used in a cross-language environment.
The CLI has a set of libraries called the Base Class Library (BCL). The entire BCL is
CLS-compliant.
The C# Environment
13
CHAPTER 1

Metadata provides the capability for code to be self-describing. This is a powerful con-
1
cept, enabling components to expose their capabilities for use in various tools. Metadata
also allows program capabilities to be dynamically implemented through runtime method

ENVIRONMENT
calls. This is used for any late bound requirements and for software development tools.

THE C#
Through the CTS, CLS, and metadata, the CLI is able to support a robust Virtual
Execution System (VES). Services provided by the VES include managed code execution
and security. The VES operates on Common Intermediate Language (CIL) code pro-
duced by CLI-compliant compilers.

Note

Managed code refers to the way the VES handles memory allocation and code
execution. The VES has full control over managed code in order to provide secu-
rity. Managed code is compiled to an intermediate language, CIL, where it can
be verified by the VES. Traditional languages such as C and C++ are considered
unmanaged because they compile to machine code and have only those con-
trols a programmer establishes in the code.
All C# code is managed code.
An often-confused concept is the difference between managed code and unsafe
code. C# has a way of allowing programmers to use certain language elements
that are considered unsafe. These are language elements such as pointers and
memory allocation on the stack. One of the primary advantages of unsafe code
is to interface with APIs that require pointers in their parameters or within a
structure. Although there is potential to do unsafe things in unsafe code, even
unsafe code is managed.

Base Class Libraries


The CLI’s Base Class Library (BCL), an entire suite of libraries, is designed to support
multiple languages. The level of CLI compliance is defined by what subset of these
libraries is implemented. So far, there are three BCL Profiles proposed for the ECMA
standard: the kernel profile, the compact profile, and the complete profile. An implemen-
tation can include more, but not less, support for official compliance certification. Figure
1.1 shows the relationship between the libraries. At the center is the kernel profile. The
compact profile includes all its libraries in addition to what’s in the kernel profile.
Likewise, the complete profile includes itself and all other libraries.

Note
C# Basics
14
PART I

Note

Currently there are plans to ship four languages with .NET. These languages are
Visual Basic.NET, Visual C++.NET, Visual Jscript.NET, and (the one near and dear
to my heart) Visual C#.NET. Currently there are approximately 50 other ISVs that
are considering porting languages to the .NET platform.

FIGURE 1.1
CLI profiles.

The Kernel Profile


The kernel profile is the minimal amount of library support an implementation can pro-
vide to call itself CLI-compliant. This is the smallest footprint that can still support C#
and a VES.

The Compact Profile


The compact profile is specified primarily for small implementations such as embedded
devices. It typically would be used in resource-constrained environments.
The C# Environment
15
CHAPTER 1

The Complete Profile 1


The complete profile includes all 25 packages of the CLI. This is a fairly complete suite

ENVIRONMENT
of libraries, enabling support for a diverse range of services. A typical environment for

THE C#
this profile would be those intended for desktop or server deployment.
Appendix B, “The .NET Frameworks Class Libraries,” contains an overview of libraries
available and details the profiles they are part of.

Standardization
On October 31, 2000, Hewlett-Packard, Intel, and Microsoft jointly submitted C# and the
CLI to the European Computer Manufacturers Association (ECMA) for standardization.
The purpose of this was to establish a standard for future implementations of C# and
the CLI.
This is significant because historically speaking, most languages are created, released,
and available for years before standardization occurs. Then after multiple incompatible
versions have been implemented, vendors play catch-up to mitigate the effects of non-
standard portions of their implementations. Furthermore, applications written with
nonstandard implementations break and need modification to comply with the new
standards-based compilers upon release. In a rare historical occurrence, this is an
opportunity to have a language open to a public standards organization (such as ECMA)
from the beginning, creating an optimistic outlook for a new entry in cross-environment
program compatibility.
Of significant note is the recent mass adoption of the Java programming language/
environment. Although this is not a public standard, it still proves the interest in a
standardized environment with a philosophy of “write once, run anywhere.” I believe
there is great potential for the C# programming language and CLI environment to
achieve these goals also. Standardization increases the probability of cross-environment
adoption of a common standard.
The primary focus in standardizing the CLI and C# is for cross-language compatibility—
so that anyone can write a component in any .NET-compatible language and that same
component may be reused in any other .NET-compatible language. The term reuse
relates to any object-oriented employment of a component to include inheritance, con-
tainment and encapsulation, and polymorphism.
The CLI also promotes standardization by implementing common Internet protocols and
standards into its core libraries. The technologies of HTTP, SOAP, and XML are well
known and accepted. They enable CLI applications such as Web services to interoperate
C# Basics
16
PART I

in a platform-neutral manner with Web services created with any other technology. The
CLI is simply a specification of a framework that enables developers to create standards-
compatible components that interoperate with any other standards-compatible component
implementations.

The .NET Architecture


The .NET (pronounced “dot net”) architecture is Microsoft’s implementation of the CLI,
plus several packages to support user interfaces, data and XML, Web services, and a base
class library. The .NET architecture is broken into three primary subsets: Common
Language Runtime, Libraries, and Languages. Figure 1.2 shows the .NET architecture.

FIGURE 1.2
The .NET
architecture.

Common Language Runtime (CLR)


The Common Language Runtime (CLR) is synonymous with the Virtual Execution
System (VES) in the Common Language Infrastructure (CLI) specification. The primary
goals of the CLR are to simplify development of applications, provide an execution envi-
ronment that is robust and secure, make deployment and management easier, and support
multiple languages.

Libraries
The .NET libraries have much more functionality than the CLI specification. Extra
enhancements include ASP.NET (Web application programming tools), Windows Forms
(interface to the Windows operating system), and ADO.NET (database connectivity
tools). The goals of the .NET libraries were to use common Web standards as their foun-
dation, unify disparate application models, enhance simplicity, and make the entire
framework factored and extensible.
The C# Environment
17
CHAPTER 1

Languages 1
The .NET Framework software development kit ships with four programming languages:

ENVIRONMENT
C++, Visual Basic, JScript, and C#. Many more third-party companies have begun work

THE C#
on additional .NET-compatible languages. What makes the .NET support for languages
so unique is that all languages are first-class players. The goal is to make them work
interchangeably. While this is mostly true, there are differences between languages and
the user must ultimately decide which language best suits his needs. This book will show
how to use C# in filling a very wide range of development requirements.

Where C# Fits In
Traditionally, languages and their libraries have been referred to as single entities.
Programmers knew they were separate, but since the library only worked with that lan-
guage, there was no harm in saying certain functionality was a part of a certain language.
With C# this is different. The libraries belong to the CLI. The language itself is very
simple and it uses the CLI libraries. These are the same libraries used by other CLI-
compliant languages. Therefore, they can’t be considered specifically C# libraries.
C# played a significant part in the development of the .NET Framework libraries. Of
course, there are other library modules written with two other CLI-compliant languages:
Visual Basic.NET and Managed C++. This means that while programming in C# and
using CLI libraries, the classes being used are very likely written in other languages.
Since this is totally transparent, it should be of no concern. However, it does prove that
the cross-language philosophy of the CLI specification does indeed work.

Summary
This chapter introduced the Common Language Infrastructure (CLI). The CLI consists of
a Common Type System (CTS), a Common Language Specification (CLS), metadata,
and a Virtual Execution System (VES).
The significance of standardization and how it could benefit the software development
community was discussed.
I also talked about the .NET Architecture. The software in this book was developed with
.NET.
Finally, there was a discussion on where C# fits into the CLI. C# is a new object-oriented
language, designed from the ground up to support the component concepts intrinsic to
the CLI. The C# programming language played a major role in the development of the
.NET Frameworks.
Getting Started
CHAPTER 2 with C#

IN THIS CHAPTER
• Writing a Simple C# Program 20

• Comments 22

• Identifiers and Keywords 24

• Style 26

• Preparing a Program To Run 27

• Basic C# Types 28

• Definite Assignment 37

• Basic Conversions 38

• Arrays 40

• Interacting with Programs 43


C# Basics
20
PART I

This chapter starts by creating a simple, minimal C# program that will give you a feel for
what C# looks like and will be a stepping-stone to more features. This chapter includes
instructions on how to compile this program. When needed, additional compilation fea-
tures will be presented. Appendix A has a detailed list of compilation options.
This chapter also provides coverage of the C# data types. It tells about the various types
C# provides. There will be plenty of examples of declarations and the kinds of data that
can be stored. It also covers the relationship between types and how to make conver-
sions. The chapter will finish by showing various ways to provide input and output for
programs.

Writing a Simple C# Program


Let’s dig in. For this first program, Listing 2.1 shows the near-minimal amount of code
necessary to write a C# program. When it executes, it will print the words “Howdy,
Partner!” to the console.

LISTING 2.1 A Simple C# Program


1: /*
2: * FileName: HowdyParner.cs
3: * Author: Joe Mayo
4: */
5:
6: // Program start class
7: public class HowdyPartner
8: {
9: // Main begins program execution
10: public static void Main()
11: {
12: // Write to console
13: System.Console.WriteLine(“Howdy, Partner!”);
14: }
15: }

Line 7 of Listing 2.1 shows a class declaration. Classes are what C# uses to declare or
define objects. They describe the attributes and behavior of an object. An object is any-
thing that has attributes and behavior. While classes are definitions, objects are the actual
entities that exist when the program runs. There can normally be many objects based
upon a single class declaration. Objects are the building blocks of the C# programming
language. C# is an object-oriented programming language; therefore, it has a starting
object. That’s what this class represents—the starting object of this program.
Getting Started with C#
21
CHAPTER 2

For C++ Programmers

The Main() method is located inside of a class instead of by itself. Also, the
method’s first letter is capitalized.

For Java Programmers

C# is case sensitive. The first letter of the Main() method is capitalized. Also, the
C# Main() method can declare return types of both int and void. 2

GETTING STARTED
WITH C#
The identifier, or name, of a class follows the class keyword. This class is called
HowdyPartner. Classes can have almost any name, but whatever the name, it should be
meaningful. Details of identifiers and keywords are described in a couple more sections.
Left and right braces indicate the beginning and ending, respectively, of a block. In
Listing 2.1, the beginning of the class block starts on line 8 after the HowdyPartner iden-
tifier, and the end of the class block is on line 15, by itself. In C#, it’s common to begin
and end portions of programs with curly braces.
There’s a method declaration on line 10. This is the Main() method. Every program has a
Main() method that is the starting point for the program. When the program begins, this
is the first method called.
There are a couple identifiers in front of the Main() method. C# Main() methods always
have a static modifier. In C# there are two types of objects—static and instance.
Instance objects are formally declared, and there can be many of the same type with dif-
ferent attributes. However, there can be only a single copy of a static object in existence
for a given program. The only way to execute a method without an instance of its con-
taining object is if that method is static. Since no instance of the starting class exists as
an object when the program starts, a static method must be called. This is why the
Main() method is static.

The other identifier is void. This is actually the Main() method’s return value. Return
values are useful for returning program status to a calling program or utility when a pro-
gram exits. When void is specified, the method does not return a value. In this case, the
Main() method does not return a value. Besides returning a void, the Main() method
could return an integer.
C# Basics
22
PART I

Within the body of the Main() method on line 13 is a single statement that causes the
words “Howdy, Partner!” to be written to the console screen. The statement System.
Console.WriteLine(“Howdy, Partner!”) writes text to the console screen. Figure 2.1
shows the output.

FIGURE 2.1
Output from the
HowdyPartner
program.

Comments
There are three types of commenting syntax in C#—multi-line, single-line, and XML.

Multi-Line Comments
Multi-line comments have one or more lines of narrative within a set of comment delim-
iters. These comment delimiters are the begin comment /*and end comment */ markers.
Anything between these two markers is considered a comment. The compiler ignores
comments when reading the source code. Lines 1 through 4 of Listing 2.1 show a multi-
line comment:
1: /*
2: * FileName: HowdyParner.cs
3: * Author: Joe Mayo
4: */

Some languages allow embedded multi-line comments, but C# does not. Consider the
following example:
1: /*
2: Filename: HowdyPartner.cs
3: Author: Joe Mayo
4: /*
5: Initial Implementation: 04/01/01
6: Change 1: 05/15/01
7: Change 2: 06/10/01
8: */
9: */
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of The man who
knew everything
This ebook is for the use of anyone anywhere in the United States
and most other parts of the world at no cost and with almost no
restrictions whatsoever. You may copy it, give it away or re-use it
under the terms of the Project Gutenberg License included with this
ebook or online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the country where
you are located before using this eBook.

Title: The man who knew everything

Author: Randall Garrett

Release date: April 29, 2024 [eBook #73495]

Language: English

Original publication: New York, NY: Ziff-Davis Publishing Company,


1956

Credits: Greg Weeks, Mary Meehan and the Online Distributed


Proofreading Team at http://www.pgdp.net

*** START OF THE PROJECT GUTENBERG EBOOK THE MAN


WHO KNEW EVERYTHING ***
Pst! This is top secret. Don't let
it get around, but we've got the
Russians right where we want
them. They haven't got a secret
left to their name. We know
every detail. You see, the
Russians were pretty sure their
inner circle was leakproof, that
no one could penetrate their
vaults. But they reckoned
without—

THE MAN WHO KNEW


EVERYTHING

By RANDALL GARRETT

[Transcriber's Note: This etext was produced from


Fantastic October 1956.
Extensive research did not uncover any evidence that
the U.S. copyright on this publication was renewed.]
He was sure of only one thing—he had a headache.

Dr. H. Wolstadt sat in a small, very secret laboratory in Arlington,


Virginia, and twisted the dials on an oscilloscope. A pale green line
wriggled up and down on the screen, and Dr. Wolstadt watched it
with anticipation.
"If this works," he muttered softly, more to himself than to his
assistant, "we will have a communication beam that will be better
than radio."
The green line wriggled and changed form. Slowly, as the physicist
manipulated the controls, the green line stopped moving.
"There!" shouted Wolstadt, "that is the wave form we want!" He
reached over toward a switch. "Check your meters, Magruder!"
The assistant carefully adjusted the recording instruments of the
huge machine that filled half the laboratory. "All right, Dr. Wolstadt,
we're ready."
"Good!" Wolstadt pressed the switch.
The assistant watched the meters and automatic graphs.
"I'm afraid it didn't work, sir," he said at last. "The instruments aren't
reacting as you expected."
Wolstadt shrugged resignedly. "Nevertheless, I think we are on the
right track. Come, my boy, we will try again."
He shut off the machine.
The machine hadn't done what the scientists had expected of it, but
it had another effect which was entirely unknown to them. During the
few seconds of operation, an invisible ray had been beamed out of
the machine. At the speed of light, the ray went through the wall of
the lab and into Dr. Wolstadt's study. Like an X-ray, it went through
the books and references on the physicist's desk. In a straight line, it
shot out of the laboratory, silent and invisible. A mile or so farther on,
it struck the Pentagon Building and went through. Among other
things, it went through a complete copy of the Encyclopedia
Brittannica, Roget's Thesaurus, the Oxford Unabridged Dictionary, a
twenty volume set of The History and Analysis of Military Tactics,
and a copy of Amazing Stories that some general had left on his
desk.
Like a flashlight going through plateglass, the beam went through
files, papers, memorandums, abstracts, reports, desks, chairs, brick,
stone, and concrete. Through the Pentagon and across the Potomac
it went, through building after building, unnoticed and invisible.
Then, on the far side of Washington, D.C., several miles from the
laboratory of Dr. Wolstadt, it struck the head of a human being.

Philip Merriwether was a nobody. He made thirty-five dollars a week


at a very dull job and lived in a cheap rooming house that had been
built around 1880 and not remodeled since. He was still wearing a
suit he had bought in 1947, and on his thin, five-foot-four frame, it
looked even older. His education had stopped at the sixth grade, and
he had almost flunked out of that. He had a mousy face, stringy hair,
and a dull look in his eyes.
In other words, he was just about as nobody as a human being can
get without being an absolute bum.
It wasn't that Phil Merriwether was really stupid; he was simply
afflicted with an incredibly bad memory. He could forget more in five
minutes than he could learn in five years. Oh, he could remember
commonplace things easily enough—his name, where he lived,
things like that. He could read and write tolerably well, although his
spelling was intolerable. He could add and subtract with fair ease,
but, having forgotten most of the multiplication table, he found
"higher mathematics," such as long division, almost impossible to do
without hours of laborious thinking.
In a way, his poor memory was economically useful. Phil loved to
read mystery stories, and, having collected a total of fifty-seven
paperback editions of the better detective novels, he found that there
was no necessity of buying more, because he could re-read the old
ones. By the time he got around to them again, he had forgotten the
plot and the identity of the murderer. Naturally, he never tried to
solve any of them; he could never remember the clues.
In routine work, Phil Merriwether was fairly efficient. If he did
something every day, he could remember it overnight, and could do
it again the next day. But his superiors soon found out that it was
almost disastrous to give him a vacation, because he had a
tendency to forget what he was supposed to do when he came back
to work. That is, if he remembered to show up for work.
In spite of all that, Phil was a nice sort of fellow. He was likable, in a
dull sort of way, and got along with most of his fellow workers. He
couldn't tell funny stories, of course, nor play a decent game of
cards, but he was an excellent conversationalist because, no matter
what was said to him, he could never think of an argument against it.
He was a good listener because he hadn't anything to say.
But his favorite pastime was walking. He liked to stroll around the
nation's capital, taking in the sights, and just plain enjoying himself.
He always walked the same route every night; if he didn't, he was
likely to get lost. Once, several years earlier, he had taken a wrong
turn and ended up in unfamiliar territory. He had asked a passer-by
how to reach his address, but had forgotten the instructions, and so
had ended up hopelessly lost. He had finally been forced to take a
taxi home, a luxury he could ill afford. After that, he stuck to his
routine.
It was on one of these evening strolls that a very peculiar thing
happened to Philip Merriwether. He was walking slowly along the
sidewalk, carefully minding his own business, when, without warning,
there was a strange, buzzy feeling in his head. It grew stronger; it felt
like someone was playing a fire-hose on his brain. His skull felt as
though it were suddenly being filled with a vast, overpowering torrent
of words—hundreds of words; thousands of words; millions upon
millions of words!
Under the pressure of this verbal onslaught, Philip Merriwether's
mind reeled. He pressed his palms to his temples and fainted dead
away.

When he came to, there were several passers-by crowded around


him. One of them was kneeling by his side, taking his pulse.
"Ha—Wha—what happened?" he asked, unoriginally enough.
"You fainted," said the man who was taking his pulse. "Just lie still;
it's all right. I'm a physician."
"Fainting," said Phil, "is normally a mild form of shock in which the
blood vessels of the abdomen become distended and engorged with
blood, thus reducing the blood pressure and temporarily depriving
the brain of its normal oxygen supply, which causes momentary loss
of consciousness."
The doctor blinked. "What? Oh. Yes. That's quite correct, sir. Do you
have these attacks often."
Phil's mouth had remained open after his last word. After a minute,
he gulped. "Did I say that?"
"What?" the doctor asked for a second time. "Do you feel all right?"
Phil Merriwether stood up hastily. "My head feels a little funny, but I
think I'm all right."
"If you want to go to a hospital—"
"No, no, thank you. I'm all right, really I am. I feel completely
resuscitated, thanks to your therapeutic ministrations."
"Think nothing of it, sir. My duty, you know," said the physician.
"The Oath of Hippocrates," said Phil, "makes it obligatory for the
physician to alleviate suffering, illness, and infirmity, and induce
salubrity in his fellow man in the most efficacious manner at his
command."
"Uh, yes, of course," said the doctor, looking baffled. "Well, good
luck." With that, he picked up his black bag and walked rapidly off in
the opposite direction. The other passers-by had already gone about
their business.
Phil, meanwhile, began walking towards his home, his head still
feeling a little peculiar. What was the matter with him? What had
happened? And where on Earth had he gotten all those big words?
Polysyllabic vocables, said a voice in his mind, although recognized
by the erudite as not being necessarily indicative of scholarly
attainments, are nevertheless profoundly impressive to the hoi polloi.
Phil nodded slowly to himself. Yeah, big words were impressive, all
right. But where had he picked them all up?
"I'd better go home and take an aspirin," he said aloud.
Aspirin, said the voice, is the acetic acidester of salicylic acid, a
white, crystalline solid having the empirical formula—
Holding his hands to his ears, Philip Merriwether ran home as fast as
his spindly legs could propel him.

B. J. Holly, office manager for Starr & Sons, Inc., flipped a switch on
his desk intercom. "Where is Merriwether?" he snapped. "That boy
was supposed to have picked up these letters for filing half an hour
ago. I can't wait any longer."
"Mr. Merriwether phoned in this morning, sir," said the secretary's
voice. "He said he was a little ill, and he'd be late. He—oh! Just a
moment, sir; he just came in."
"Send him in here!" ordered B. J. Holly.
Mr. Holly frowned at Phil Merriwether as soon as the door opened.
"Under the weather a bit, eh, Merriwether?"
Phil nodded. "Yes, sir. My head feels queer."
Mr. Holly suppressed an impulse to remark that he wasn't at all
surprised. In his estimation, anyone with a head like Merriwether's
would feel odd all the time. But Mr. Holly, although somewhat
tyrrannical, and definitely a stuffed shirt, was not basically cruel, so
he said nothing that vicious.
"A bit of a hangover, perhaps?" he asked suspiciously.
Phil was picking up the papers for the file room. "No, sir," he said
absently. "A hangover is caused by the toxic effects of various
isomeric forms of higher alcohols and other impurities normally
present in alcoholic beverages, plus a depletion of vitamins,
especially B-one, in the system. I don't drink."
"I—uh—I see." But Mr. Holly did not see. He was totally baffled. He
watched in astonishment as Phil Merriwether walked out the door of
the office.
Merriwether, himself was slightly bemused. How had he done it? He
knew perfectly well what he was saying; a full night of thinking had
managed to bring to him the realization that something—he knew not
what—had happened to his memory. It seemed to him that there
must be something he could do with it, but he didn't quite know what.
The decision was practically forced upon him just before lunchtime.
He was putting on his coat to go out for lunch when B. J. Holly
stepped out of his office. The office manager was preparing to have
lunch with an out-of-town buyer, and as he stepped up to the visiting
fireman, he said: "Well, as General Pershing said: 'Lafayette, we are
here!'" He chuckled at his own wit, paying no attention to
Merriwether.
"I beg your pardon, sir," said Phil, "but the general never said that; as
a matter of fact, he said later that it was put into his mouth by a
newspaperman. He said—"
B. J. glowered at him. An office boy, even if he is thirty-four years of
age, is not supposed to contradict his superior.
"Look, son," said B. J., "I happened to be there. I was only a private,
but I happened to be standing right next to him."
"That's impossible, sir," Phil said quietly. "According to Federal
records, you were born on April second, nineteen-oh-four. You were
only fourteen years old at the time. You have no military record with
the United States Army."
The out-of-town buyer suppressed a snicker. B. J. Holly turned
purple and said: "I'll see you after lunch."

After lunch, Philip Merriwether lost the job he had held for five years.
At seven o'clock that night, he sat in a small bar, sipping
disconsolately at a glass of Coca-Cola. Not knowing where he was
going to get another job, he was trying to drown his thoughts in
soda-water and television. The show on the screen was "You Can't
Lose," a quiz show produced by the Boltman Automobile
Corporation.
The quizmaster was grinning sardonically at the hapless contestant.
"You have arrived at the fifty thousand dollar question," he said.
"Since you chose geometry as your category, the question will be on
that subject. Are you ready?"
The contestant nodded unhappily.
"All right, here's the question: What is the value of pi to eight decimal
places?"
Before the contestant could say a word, Phil muttered: "Three point
one four one five nine two six five—plus." He didn't notice what the
contestant said, but the quizmaster shook his head in mock sorrow.
"I'm sorry, sir, but the correct answer is: three point one four one five
nine two six five. Better luck next time."
The coarse, unshaven man standing next to Phil looked at him in
awe. "Hey, buddy," he said, "that's the ninth time you've answered
right. Why don't you get on that program and make yourself some
dough?"
Phil blinked at his Coke and thought it over. Then his face
brightened. "Yeah," he said, grinning, "why don't I?"

It took him three weeks to get into the studio, and by that time, his
severance pay was almost gone. He was nearly broke, and had no
prospects of a job. He had to make good.
By pure chance, he was chosen as one of the first contestants. The
quizmaster beamed at him pleasantly.
"You understand the rules, don't you?" he asked. "All you have to
do...."
He went on, but Phil didn't hear him; he was too scared. When the
first question popped up, he said: "I beg your pardon?"
"I'll repeat the question," the quizmaster said. "You have chosen the
'General Category.' That pays twice as much, but it means I can ask
you any question I like. The first one was: 'Who were the Essenes?'"
Since the General Category questions paid off twice as much as the
Restricted Categories, they were about four times as hard. But that
didn't bother Phil Merriwether in the least.
"The Essenes," he said, "were an obscure Jewish sect which
flourished during the time of Christ, from before 100 B.C. to about 70
A.D. They are believed to be instrumental in the composition of the
so-called Dead Sea Scrolls, which were discovered—"
"That's enough," the quizmaster said. "You've given the right
answer!" The orchestra sounded a chord. Applause followed.
"Second question: Listen carefully. Henry the Seventh's title was the
same as the title of the last Tudor king of England; the last Tudor
king had the same name. What was the name of the last Tudor ruler
of England?" The quizmaster smirked happily; the question was a
trick one.
"Elizabeth the First was the last Tudor ruler," said Phil. "The last
Tudor king was Henry the Eighth."
Naturally, the answer was right.
"Very good," said the quizzer. "Number three: what does
pneumonoultramicroscopicsilicovolcanoconiosis mean?"
Phil closed his eyes and listened to the little voice inside his head.
He said: "It is an inflammation of the lungs caused by tiny particles of
rock dust; it is commonly known as 'silicosis' or 'miner's
consumption.'"
The quizmaster looked almost shocked, but, good showman that he
was, he managed to keep a bland expression on his face.
"That's right!" he bellowed.
Phil Merriwether grinned happily. He didn't know how it had come
about, but, somehow, something had filled his head full of all kinds of
amazing facts. It didn't matter what the question was, all Phil had to
do was think about it, and the answer was in his memory. He smiled,
waiting for the next question.
"You've come to the $25,000 question," said the MC. "If you want to
go on, you will have to be put in a soundproof booth so that you
won't be prompted by the audience. If you want to come back next
week—"
"I'll take it now," said Phil Merriwether.
So they put him in a soundproof booth. All he could hear was the
announcer's voice.
Phil smiled to himself. Twenty-five thousand dollars so far! It was
fantastic! He'd never have to work again!
He answered the next question easily. Fifty thousand dollars!
Fantastic!
The announcer said: "What is the mathematical formula for the
world's most powerful weapon?"
Phil grinned. That was simple. "The formula is: i over b times a
equals pi to the i times e over mu," he said.

"Ohhh, I'm sorry, sir," the announcer said sadly. "The basic formula
for the manufacture of the atomic bomb is: E equals m times c
squared. But you still have your fifty thousand dollars;
congratulations and better luck next time."
Phil Merriwether blinked. He could hardly believe it. He knew his
answer was right. There must be a mistake. But no amount of
argument did him any good. Within fifteen minutes, he was out on
the street. The studio had promised that the check would be
deposited to his account in the morning. Phil shrugged and went
home.

At midnight, Philip Merriwether woke up suddenly to see the glare of


a flashlight being shone in his face.
"Are you Philip Merriwether?" growled a voice.
"Yes, I am. What's the meaning of this?"
The lights in the room went on to reveal five men with drawn guns
standing outside the door. As they came into the room, the man with
the flashlight flicked it off. "Search the room," he said to the others.
As they methodically began their search, Phil said: "What's going on
here? Who are you?"
"FBI," snapped the man who was obviously the leader of the group.
"Are you sure you're Philip Merriwether? We'll be taking your
fingerprints shortly, so it won't do you any good to lie."
"Certainly I'm me!" Phil snapped, irritated. "What makes you think I'm
not?"
"Never mind," said the Federal agent.
The truth was that Merriwether no longer looked like the lackluster
character he had been a few weeks before. His eyes had a sparkle
to them, his body had more springiness. He looked more alive. He
was no longer the colorless man he had been.
"Nothing unusual in the room, sir," said one of the men who had
been searching.
"Okay," said the leader to Merriwether, "put on your clothes. You're
coming with us."
"You can't arrest me!" Phil said. "I haven't done anything. What is the
charge?"
"Espionage," said the FBI man without blinking an eyelid.
They put him in a big, powerful Cadillac and drove him through the
streets of Washington to an office building near the Capitol. Most of
the city was asleep, but this building was ablaze with light. The FBI
men parked the car and led Phil into the building. They were greeted
by a reception committee the like of which Phil had never seen
before.
Two generals, including the Chief of Staff, a couple of admirals, an
Air Force general, and a half dozen important-looking civilians, one
of whom Phil recognized as the Secretary of Defense himself!
They sat Phil down in a chair without a word, and just looked at him
for a few seconds; then the Secretary of Defense said: "What do you
know about the Q-beam?"
"The Q-beam," Phil told him, "is a top-secret weapon. It is a ray
which is capable of paralyzing without killing, and can operate over a
distance of several hundred miles. The basic formula is—"
"Never mind what it is!" snapped the Chief of Staff. "The whole
United States heard you give it out over the air this evening!"
"What else do you know about our defenses?" the Secretary asked.
Phil told them. He knew how big the atomic stockpiles were, where
the bombs were, and how they were to be used. He knew everything
about the ICBM rocket program and where the launching sites were.
He knew where every ship in the Navy was and what sort of
armament it carried. He told them where the secret airbases were
hidden and how many bombers were at each.

As he continued, the officials became more and more nervous. They


fidgeted as each new piece of information was disclosed, and the
flow of information seemed endless.
At last the Secretary of Defense said: "That's enough!" His face was
white. He turned to the others. "Gentlemen, I think we can say
without doubt that we have captured the most cunning, clever, and
dangerous spy in the world. The question is: What shall we do with
him?"
"How did you get this information?" one of the generals asked.
"I don't know," Phil said truthfully. "It just came to me."
"He won't talk," said an admiral.
"Who do you work for?" asked another.
"I used to work for Starr & Son, but they fired me three weeks ago."
"I mean, what country?"
"I don't work for anybody!"
The Secretary of Defense looked up at the FBI man.
"I want everything on this man—everything! He has to be
investigated as no other man has ever been. If possible, we want to
know what this man has been doing every second of his life ever
since he was born!"
The FBI man nodded. "I'll have to check with the Chief, of course,
but I'm sure we can put every man in the Bureau on this job."
The Secretary nodded. "A few kidnap cases and things like that will
have to wait, but that's nothing compared to this."
The FBI man left, and the other men began grilling Phil Merriwether
again. It went on for hours.

Phil Merriwether sat in the deepest, most secluded cell of the United
States Government's greatest security prison. He sat and thought,
his brain working more furiously than it had ever worked before. He
was tired and haggard from loss of sleep, and worn out from hours of
questioning. But that wasn't the worst of it. The entire top brass of
the government was in a stew over what they should do with Philip
Merriwether. The FBI could get no evidence on him; there was
nothing to prove he was a spy. And even if there had been, the case
could never be brought to court. Phil knew too much.
"Good heavens," he moaned, "how did I ever get into a fix like this?"
"You're a blabbermouth," he answered himself. "If you hadn't told
them all that stuff, you'd never have been in this jam!"
But how did he know all the information about the U.S.
Government's most top secret plans? It must have had something to
do with that fainting spell. How did that explain it?
"Well," he said to himself, "you've got a lot of information—use it!"
So he sat on the edge of the hard bunk, his mind searching for some
clue as to what had happened to him.
He was still sitting like that when the Secretary of Defense and the
President of the United States walked into the cell some hours later.
He had thought about all the data he had on every subject from
anthropology to zoology. It had something to do with neurology and
radiation physics, he was sure, but what?
And then, quite suddenly, the pieces clicked together.
When the Chief Executive walked into his cell, Phil beamed happily.
"I'm pleased to meet you, Mr. President."
The President frowned. "I must admit, Mr. Merriwether, that it is a
pleasure to meet you, too. I admire such abilities as yours, although I
also wish you had never been born. It seems you know more about
our national defense than I do."
"It's amazing," said the Secretary. "According to the FBI, this
fiendishly clever man has been masquerading as an ordinary
blockhead for more than thirty years. No one suspected his true
genius. The only thing we can't figure out is why he shot off his
mouth over television."
Phil said: "Mr. Secretary, I didn't think about it. I didn't realize it was
so secret. I'm sorry. But I think I can show you how I got all this
information."
The President looked blank. "Show us? You mean you're willing to
betray your espionage system?"
"I don't have any spy system," Phil said. "Will you give me a pencil
and a piece of paper?"
The Secretary handed him a notebook and a ball-point pen, and Phil
began to write. "According to File X-99761, in the War Department's
Ultra Top Secret Section, a Dr. Heinrich Wolstadt is working on a
secret communication device. I'm putting some formulas on this
paper. Ask Dr. Wolstadt what effect this particular wave form would
have on the human brain."
The Secretary of Defense and the President looked at each other.
"I guess we might as well," the President said.

It was several hours later that Dr. Wolstadt was rushed into Phil's
cell. He was so excited that his German accent became much
heavier than usual.
"Is this the chentleman? Ach! It's amazing! How did it happen? You
were standing right in the path of the ray, nein?"
"I think so, Dr. Wolstadt. Didn't you suspect what effect the beam
might have had?"
"Never!" said the physicist. "Not until I saw your mathematics. It's
unbelievable to think this could happen!"
"For Heaven's sake!" said the President. "What happened?"
Wolstadt turned around to face the Chief Executive.
"It's very simple. The derivation of the Q-beam that I have been
working on got out of control for a second. It went through all my
files, and all the files in the Pentagon, and Heaven only knows what
else. It picked up all that information and put it in Mr. Merriwether's
mind!"
"Amazing!" said the President.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookgate.com

You might also like