Radek Vystavěl

C# Programming for Absolute Beginners

Radek Vystavěl

Ondřjov, Czech Republic

Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress.com/9781484233177. For more detailed information, please visit www.apress.com/source-code.

ISBN 978-1-4842-3317-7

e-ISBN 978-1-4842-3318-4

https://doi.org/10.1007/978-1-4842-3318-4

Library of Congress Control Number: 2017962139

© Radek Vystavěl 2017

This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.

Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.

While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.

Printed on acid-free paper

Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.

To my parents whose loving care allowed me to live an untroubled childhood and to develop my talents in exact sciences. Let this book be a celebration of their efforts, not having been, hopefully, in vain.

Mým rodičům, jejichž láskyplná péče mi umožnila prožít bezstarostné deˇtství a rozvinout nadání pro exaktní vědy. Ať je tato kniha oslavou jejich úsilí, které, doufám, nepřišlo vniveč.

Acknowledgments

Special thanks to my daughter, Amálie, who assisted me in preparing the manuscript. She typed a large portion of it and prepared many figures, upon my instruction.

Thanks also to the whole Apress team, technical reviewers included, whose expertise and drive allowed the book to be completed properly and on time. Especially I appreciate the e-mail discussions with Gwenan Spearing concerning the philosophy of the book, as well as her suggestions, which substantially improved it. Also, the book got much better due to the hard work of Kim Wimpsett, who kindly polished my English.

Table of Contents

  1. Chapter 1:​ Getting Ready
    1. C# Language
    2. Who This Book For
    3. How the Book Differs from Others
    4. How to Work with the Book
    5. What to Install on Your Computer
      1. Development Environment
      2. Visual Studio
      3. Windows Versions
      4. Non-Windows Operating Systems
    6. Installation
      1. Free Registration
    7. Summary
  2. Part I: Data 9
    1. Chapter 2:​ Your First Program
      1. Seeing It in Action
      2. Creating the Project
        1. Launching Visual Studio
        2. Working with the New Project Dialog
      3. Writing the Program Code
        1. The Look of the Development Environment
        2. Knowing Where to Write Statements
        3. Writing the Code
        4. Understanding Your First Statements
        5. Using IntelliSense
      4. Saving the Project
      5. Launching Your Program
        1. Note
      6. Changing Text Size
      7. Dealing with Errors
      8. Finishing Your Work
      9. Restoring Your Work
      10. Transferring Your Work
        1. Transferring the Project
        2. Transferring the Program to Others
      11. Using Solution Explorer
      12. Summary
    2. Chapter 3:​ Dealing with Output
      1. Producing Numeric Output
        1. Task
        2. Solution
        3. Discussion
      2. Making Calculations
        1. Task
        2. Solution
      3. Making More Complex Calculations
        1. Task
        2. Solution
        3. Discussion
      4. Joining Text
        1. Task
        2. Solution
      5. Outputting Special Characters
        1. Task
        2. Solution
        3. Discussion
      6. Using Preformatted Text
        1. Task
        2. Solution
      7. Adding 1 and 1
        1. Task
        2. Solution
        3. Discussion
      8. Summary
    3. Chapter 4:​ Using Variables
      1. Storing Text
        1. Task
        2. Solution
        3. Discussion
      2. Storing Numbers
        1. Task
        2. Solution
      3. Adding 1 and 1
        1. Task
        2. Solution
        3. Discussion
      4. Doing Calculations with Variables
        1. Task
        2. Solution
        3. Discussion
      5. Assembling a Grand Combination
        1. Task
        2. Solution
        3. Discussion
      6. Working with Decimal Numbers
        1. Task
        2. Solution
        3. Discussion
      7. Working with Logical Values
        1. Task
        2. Solution
        3. Discussion
      8. Summary
    4. Chapter 5:​ Working with Objects
      1. What Time Is It?​
        1. Task
        2. Solution
      2. What Date Is It Today?​
        1. Task
        2. Solution
      3. Working with Date Components
        1. Task
        2. Solution
      4. Using Namespaces
        1. Important using
        2. Namespaces
        3. Without usings
      5. Using the Environment Object
        1. Task
        2. Solution
      6. Summary
    5. Chapter 6:​ Using Object Actions
      1. Displaying the Month in Text
        1. Task
        2. Solution
        3. Discussion
      2. Displaying Tomorrow
        1. Task
        2. Solution
      3. Displaying a Specific Date
        1. Task
        2. Solution
      4. Rolling a Single Die
        1. Task
        2. Solution
        3. Note
      5. Rolling Two Dice
        1. Task
        2. Solution
      6. Getting the Path to the Desktop
        1. Task
        2. Solution
        3. Enumeration
      7. Summary
    6. Chapter 7:​ More About Objects
      1. Text As an Object
        1. Task
        2. Solution
        3. Discussion
      2. Numbers as Objects
        1. Task
        2. Solution
        3. Discussion
      3. Formatting Numbers
        1. Task
        2. Solution
      4. Localized Output
        1. Task
        2. Solution
      5. Concluding Notes
        1. Static Objects
        2. Classes
        3. Relation Between Class and Object
        4. Special Classes
        5. Structures
      6. Summary
  3. Part II: Calculations 93
    1. Chapter 8:​ Input
      1. Text Input
        1. Task
        2. Solution
      2. Better Input
        1. Task
        2. Solution
        3. Discussion
      3. Numeric Input
        1. Task
        2. Solution
        3. Discussion
      4. Calculation with Entered Number
        1. Task
        2. Solution
      5. Ten More
        1. Task
        2. Solution
      6. Addition
        1. Task
        2. Solution
      7. Incorrect Input
        1. Task
        2. Solution
        3. What Happened
        4. Interior of the catch Part
        5. Complete Solution
        6. Testing
        7. Explanation
      8. Summary
    2. Chapter 9:​ Numbers
      1. Decimal Input
        1. Task
        2. Solution
      2. Localized Numeric Input
        1. Task
        2. Solution
        3. Testing and Conclusions
      3. Basic Arithmetic
        1. Task
        2. Solution
      4. Mathematical Functions
        1. Task
        2. Solution
        3. Discussion
      5. Integer Division
        1. Task
        2. Solution
        3. Discussion
      6. Summary
    3. Chapter 10:​ Economic Calculations
      1. Currency Conversion
        1. Task
        2. Solution
      2. Total Price
        1. Task
        2. Solution
        3. Discussion
      3. Commissions
        1. Task
        2. Solution
        3. Discussion
      4. Rounding
        1. Task
        2. Solution
      5. Further Rounding
        1. Task
        2. Solution
      6. Value-Added Tax
        1. Task
        2. Analysis
        3. Solution
      7. Summary
    4. Chapter 11:​ Calculations with Dates
      1. Date Input
        1. Task
        2. Solution
        3. Discussion
      2. Single Month
        1. Task
        2. Solution
        3. Discussion
      3. Quarter
        1. Task
        2. Analysis
        3. Solution
      4. Date Difference
        1. Task
        2. Solution
      5. Time Zones and UTC
        1. Task
        2. Solution
      6. Summary
    5. Chapter 12:​ Understanding Different Kinds of Numbers
      1. More Numeric Types
        1. Task
        2. Solution
        3. Discussion
      2. Memory Consumption
        1. Task
        2. Solution
        3. Connections
        4. Discussion
      3. Overflow
        1. Task
        2. Solution
        3. Discussion
      4. Dealing with Overflow
        1. Task
        2. Solution
        3. Settings in Visual Studio
        4. Results
      5. Summary
    6. Chapter 13:​ Accumulating Values
      1. Ten More, Revisited
        1. Task
        2. Solution
        3. Discussion
      2. Compound Assignment
        1. Task
        2. Solution
      3. Further Compound Assignments
        1. Task
        2. Solution
      4. Incrementing and Decrementing
        1. Task
        2. Solution
      5. Compound Assignment and Text
        1. Task
        2. Solution
      6. Progressive Summation
        1. Task
        2. Solution
      7. Multiple Text Join
        1. Task
        2. Solution
      8. Summary
  4. Part III: Conditionals 177
    1. Chapter 14:​ Essential Tools
      1. IntelliSense
        1. Exploring the Possibilities
        2. Examples
        3. Note
        4. Keyboard Shortcuts
      2. Documentation
        1. MSDN Portal
        2. Search
        3. Specific Class Page
        4. Common Search
      3. Debugging Tools
        1. Project
        2. Stepping Through the Code
        3. Breakpoints
        4. Memory Inspection
      4. C# Interactive
        1. What Is It?​
        2. How to Launch It?​
        3. Notes
      5. Summary
    2. Chapter 15:​ Getting Started with Conditions
      1. Password Input
        1. Task
        2. Analysis
        3. Solution
        4. Discussion
      2. Reversed Condition
        1. Task
        2. Solution
        3. Discussion
      3. Length Check
        1. Task
        2. Solution
      4. Positive Numbers
        1. Task
        2. Solution
      5. Odd and Even Numbers
        1. Task
        2. Solution
      6. Case Indifference
        1. Task
        2. Solution
      7. Without Braces
        1. Task
        2. Solution
      8. Greater of Two Numbers
        1. Task
        2. Solution
      9. Without the else Branch
        1. Task
        2. Solution
      10. Using a Built-in Function
        1. Task
        2. Solution
      11. Summary
    3. Chapter 16:​ Practical Conditions
      1. Appending Extension
        1. Task
        2. Solution
        3. Discussion
      2. Head and Tail
        1. Task
        2. Solution
      3. Deadline Check
        1. Task
        2. Solution
      4. Invoice Date Check
        1. Task
        2. Solution
      5. Spanish Day of Week
        1. Task
        2. Solution
      6. Switch Statement
        1. Task
        2. Solution
      7. Summary
    4. Chapter 17:​ Compound Conditions
      1. Yes or No
        1. Task
        2. Solution
        3. Discussion
      2. Username and Password
        1. Task
        2. Solution
        3. Discussion
      3. Two Users
        1. Task
        2. Solution
        3. Discussion
      4. Precalculation of Conditions
        1. Task
        2. Solution
        3. Discussion
      5. Yes or No Reversed
        1. Task
        2. Solution
        3. Discussion
      6. Grade Check
        1. Task
        2. Solution
      7. Better Range Check
        1. Task
        2. Solution
      8. Summary
    5. Chapter 18:​ Multiple Conditions
      1. Soccer
        1. Task
        2. Analysis
        3. Solution
      2. Soccer Alternatively
        1. Analysis
        2. Solution
      3. Minimum of Three Numbers
        1. Task
        2. Analysis
        3. Solution
      4. Minimum with Built-in Function
        1. Solution
      5. Linear Equation
        1. Task
        2. Analysis
        3. Solution
      6. Quadratic Equation
        1. Task
        2. Analysis
        3. Solution
        4. Discussion
      7. Summary
    6. Chapter 19:​ Advanced Conditions
      1. Conditional Operator
        1. Task
        2. Solution
        3. Discussion
      2. Summary Evaluation
        1. Task
        2. Details
        3. Solution
        4. Discussion
      3. Second Character Test
        1. Task
        2. Solution
        3. Discussion
      4. Summary
  5. Part IV: Loops 275
    1. Chapter 20:​ First Loops
      1. Repeating the Same Text
        1. Task
        2. Solution
        3. Solution Using a Loop
        4. Solution
        5. How the for Loop Works
        6. The Loop
        7. Explore It Yourself
        8. Tip
      2. Choosing the Number of Repetitions
        1. Task
        2. Solution
        3. Discussion
      3. Throwing a Die Repeatedly
        1. Task
        2. Solution
      4. Repeating Similar Lines
        1. Task
        2. Solution Without a Loop
        3. Solution Using a Loop
        4. Discussion
      5. Summary
    2. Chapter 21:​ Improving Loops
      1. Choosing Text
        1. Task
        2. Solution
      2. Alternating Loop
        1. Task
        2. First Solution
        3. Second Solution
        4. Third Solution
      3. Rock-Scissors-Paper
        1. Task
        2. Solution
        3. Discussion
      4. Summary
    3. Chapter 22:​ Number Series
      1. Every Other
        1. Task
        2. Solution
        3. Discussion
        4. Alternative Solution
      2. Descending Series
        1. Task
        2. Solution
        3. Discussion
      3. Decimal Numbers
        1. Task
        2. Seemingly Correct Solution
        3. Testing
        4. The Cause of the Error
        5. Correct Solution
      4. Second Powers
        1. Task
        2. Solution
      5. Two in a Row
        1. Task
        2. Solution
      6. Two Independent Series
        1. Task
        2. Solution
        3. Discussion
      7. Summary
    4. Chapter 23:​ Unknown Number of Repetitions
      1. Entering a Password
        1. Task
        2. Solution
        3. do-while Construction
        4. This Case
        5. Variable Outside of the Loop
        6. Tip
      2. Waiting for Descend
        1. Task
        2. Solution
        3. Discussion
      3. Every Week Until the End of Year
        1. Task
        2. Solution
      4. As Long As a 6 Is Being Thrown
        1. Task
        2. Solution
      5. Until Second 6
        1. Task
        2. Solution
      6. Until Two 6s in a Row
        1. Task
        2. Solution
      7. Summary
    5. Chapter 24:​ Accumulating Intermediate Results
      1. Sum of the Entered Numbers
        1. Task
        2. Solution
      2. Product of the Entered Numbers
        1. Task
        2. Solution
        3. Discussion
      3. The Greatest
        1. Task
        2. Solution
      4. The Second Greatest
        1. Task
        2. Solution
      5. Output of All Entered Names
        1. Task
        2. Solution
        3. Discussion
      6. Summary
    6. Chapter 25:​ Advanced Loops
      1. Thank God It’s Friday (TGIF)
        1. Task
        2. Solution
        3. Discussion
      2. Power
        1. Task
        2. Solution
      3. Sine
        1. Task
        2. Analysis
        3. Solution
        4. Enhancement
      4. Moon Landing
        1. Task
        2. Physical Model
        3. Solution
      5. Summary
      6. Personal Notes
        1. Dice
        2. The Sine Task
        3. Moon Landing
      7. Concluding Wish
  6. Index

About the Author and About the Technical Reviewers

About the Author

A458464_1_En_BookFrontmatter_Figb_HTML.jpg

Radek Vystavěl is a software developer based in Ondřejov, Czech Republic. During his career, he has helped many companies and academic institutions with their demands for tailor-made software. In addition, in the past 15 years, he has taught many courses about programming and databases, both at the college level and through his own events. During this time, he has acquired substantial experience teaching beginners and has decided to share it with a worldwide audience. In his leisure time, he studies physics and its history and draws his inspiration from walking in the woods and meadows.

About the Technical Reviewers

Fabio Claudio Ferracchiati is a senior consultant and a senior analyst/developer using Microsoft technologies. He works at BluArancio S.p.A ( www.bluarancio.com ) as a senior analyst/developer and Microsoft Dynamics CRM specialist. He is a Microsoft Certified Solution Developer for .NET, a Microsoft Certified Application Developer for .NET, a Microsoft Certified Professional, and a prolific author and technical reviewer. Over the past ten years, he’s written articles for Italian and international magazines and has co-authored more than ten books on a variety of computer topics.

Sean Whitesell is a software developer in Tulsa, Oklahoma, with more than 17 years of experience in client-server, web, embedded, and electronics development. He is the president of the Tulsa .NET User Group and frequently speaks at area user groups and conferences. His passions are solving problems programmatically, coding craftsmanship, and teaching. He is also a chaplain and sound engineer at his church and teaches self-defense classes to children.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.29.119