Previous Next

C Programming for Absolute Beginners, Second Edition Learn to Think Like a Programmer and Start Writing Code (Radek Vystavěl) (z-library.sk, 1lib.sk, z-lib.sk)

Author: Radek Vystavěl

C/C++/C#

Overview • Is a well-paced, accessible, and practical guide to programming that starts at the beginning • Uses real-world examples distilled to their fundamentals • Helps you experience the joy of programming by solving satisfying problems About this Book Get started using the C# programming language. Based on the author’s 15 years of experience teaching beginners, this book provides you with a step-by-step introduction to the principles of programming, or rather, how to think like a programmer. The task-solution approach will get you immersed, with minimum theory and maximum action. What You Will Learn • Understand what programming is all about • Write simple, but non-trivial, programs • Become familiar with basic programming constructs such as statements, types, variables, conditions, and loops • Think like a programmer and combine these programming constructs in new ways • Get to know C# as a modern, mainstream programming language, and Visual Studio as one of the world’s most popular programming tools Who This Book Is For Those with very little or no experience in computer programming, who know how to use a computer, install a program, and navigate the web

📄 File Format: PDF
💾 File Size: 11.7 MB
10
Views
0
Downloads
0.00
Total Donations

📄 Text Preview (First 20 pages)

ℹ️

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

📄 Page 1
C# Programming for Absolute Beginners Learn to Think Like a Programmer and Start Writing Code — Second Edition — Radek Vystavěl
📄 Page 2
C# Programming for Absolute Beginners Learn to Think Like a Programmer and Start Writing Code Second Edition Radek Vystavěl
📄 Page 3
C# Programming for Absolute Beginners: Learn to Think Like a Programmer and Start Writing Code ISBN-13 (pbk): 978-1-4842-7146-9 ISBN-13 (electronic): 978-1-4842-7147-6 https://doi.org/10.1007/978-1-4842-7147-6 Copyright © 2021 by Radek Vystavěl 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. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Joan Murray Development Editor: Laura Berendson Coordinating Editor: Jill Balzano Cover image designed by Freepik (www.freepik.com) Distributed to the book trade worldwide by Springer Science+Business Media LLC, 1 New York Plaza, Suite 4600, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm. com, 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. For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. 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/9781484271469. For more detailed information, please visit http://www.apress.com/source- code. Printed on acid-free paper Radek Vystavěl Ondřejov, Czech Republic
📄 Page 4
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é dětství a rozvinout nadání pro exaktní vědy. Ať je tato kniha oslavou jejich úsilí, které, doufám, nepřišlo vniveč.
📄 Page 5
v Table of Contents Chapter 1: Getting Ready ������������������������������������������������������������������������������������������ 1 C# Language ��������������������������������������������������������������������������������������������������������������������������������� 1 Whom Is This Book For ����������������������������������������������������������������������������������������������������������������� 2 How the Book Differs from Others ������������������������������������������������������������������������������������������������ 2 How to Work with the Book ����������������������������������������������������������������������������������������������������������� 3 What to Install on Your Computer �������������������������������������������������������������������������������������������������� 4 Development Environment ������������������������������������������������������������������������������������������������������ 4 Visual Studio ���������������������������������������������������������������������������������������������������������������������������� 5 Windows Versions ������������������������������������������������������������������������������������������������������������������� 5 Non-Windows Operating Systems ������������������������������������������������������������������������������������������� 6 Installation ������������������������������������������������������������������������������������������������������������������������������������ 7 Free Registration ��������������������������������������������������������������������������������������������������������������������� 7 Updates and Feedback ����������������������������������������������������������������������������������������������������������������� 8 Summary��������������������������������������������������������������������������������������������������������������������������������������� 9 Part I: Data ���������������������������������������������������������������������������������������������������� 11 Chapter 2: Your First Program �������������������������������������������������������������������������������� 13 Seeing It in Action ����������������������������������������������������������������������������������������������������������������������� 13 Creating the Project �������������������������������������������������������������������������������������������������������������������� 13 Launching Visual Studio �������������������������������������������������������������������������������������������������������� 14 Creating New Project ������������������������������������������������������������������������������������������������������������� 16 About the Author ���������������������������������������������������������������������������������������������������xxv About the Technical Reviewer �����������������������������������������������������������������������������xxvii Acknowledgments ������������������������������������������������������������������������������������������������xxix
📄 Page 6
vi Writing the Program Code ����������������������������������������������������������������������������������������������������������� 17 The Look of the Development Environment ��������������������������������������������������������������������������� 17 Knowing Where to Write Statements ������������������������������������������������������������������������������������� 19 Writing the Code �������������������������������������������������������������������������������������������������������������������� 19 Understanding Your First Statements ������������������������������������������������������������������������������������ 21 Using IntelliSense ������������������������������������������������������������������������������������������������������������������ 22 Saving the Project ����������������������������������������������������������������������������������������������������������������������� 22 Launching Your Program ������������������������������������������������������������������������������������������������������������� 23 Note ��������������������������������������������������������������������������������������������������������������������������������������� 25 Changing Text Size ���������������������������������������������������������������������������������������������������������������������� 25 Dealing with Errors ��������������������������������������������������������������������������������������������������������������������� 26 Finishing Your Work ��������������������������������������������������������������������������������������������������������������������� 28 Restoring Your Work �������������������������������������������������������������������������������������������������������������������� 28 Transferring Your Work ���������������������������������������������������������������������������������������������������������������� 31 Using Solution Explorer ��������������������������������������������������������������������������������������������������������������� 31 Summary������������������������������������������������������������������������������������������������������������������������������������� 34 Chapter 3: Dealing with Output ������������������������������������������������������������������������������ 35 Producing Numeric Output ���������������������������������������������������������������������������������������������������������� 35 Task ��������������������������������������������������������������������������������������������������������������������������������������� 35 Solution ��������������������������������������������������������������������������������������������������������������������������������� 36 Discussion ����������������������������������������������������������������������������������������������������������������������������� 37 Making Calculations �������������������������������������������������������������������������������������������������������������������� 37 Task ��������������������������������������������������������������������������������������������������������������������������������������� 37 Solution ��������������������������������������������������������������������������������������������������������������������������������� 38 Making More Complex Calculations �������������������������������������������������������������������������������������������� 38 Task ��������������������������������������������������������������������������������������������������������������������������������������� 38 Solution ��������������������������������������������������������������������������������������������������������������������������������� 38 Discussion ����������������������������������������������������������������������������������������������������������������������������� 39 Joining Text ��������������������������������������������������������������������������������������������������������������������������������� 40 Task ��������������������������������������������������������������������������������������������������������������������������������������� 40 Solution ��������������������������������������������������������������������������������������������������������������������������������� 41 Table of ConTenTs
📄 Page 7
vii Outputting Special Characters ���������������������������������������������������������������������������������������������������� 41 Task ��������������������������������������������������������������������������������������������������������������������������������������� 41 Solution ��������������������������������������������������������������������������������������������������������������������������������� 42 Discussion ����������������������������������������������������������������������������������������������������������������������������� 43 Using Preformatted Text �������������������������������������������������������������������������������������������������������������� 43 Task ��������������������������������������������������������������������������������������������������������������������������������������� 44 Solution ��������������������������������������������������������������������������������������������������������������������������������� 44 Adding 1 and 1 ���������������������������������������������������������������������������������������������������������������������������� 44 Task ��������������������������������������������������������������������������������������������������������������������������������������� 44 Solution ��������������������������������������������������������������������������������������������������������������������������������� 45 Discussion ����������������������������������������������������������������������������������������������������������������������������� 46 Summary������������������������������������������������������������������������������������������������������������������������������������� 46 Chapter 4: Using Variables ������������������������������������������������������������������������������������� 47 Storing Text ��������������������������������������������������������������������������������������������������������������������������������� 47 Task ��������������������������������������������������������������������������������������������������������������������������������������� 47 Solution ��������������������������������������������������������������������������������������������������������������������������������� 47 Discussion ����������������������������������������������������������������������������������������������������������������������������� 48 Storing Numbers ������������������������������������������������������������������������������������������������������������������������� 49 Task ��������������������������������������������������������������������������������������������������������������������������������������� 49 Solution ��������������������������������������������������������������������������������������������������������������������������������� 49 Adding 1 and 1 ���������������������������������������������������������������������������������������������������������������������������� 50 Task ��������������������������������������������������������������������������������������������������������������������������������������� 50 Solution ��������������������������������������������������������������������������������������������������������������������������������� 50 Discussion ����������������������������������������������������������������������������������������������������������������������������� 51 Doing Calculations with Variables ����������������������������������������������������������������������������������������������� 51 Task ��������������������������������������������������������������������������������������������������������������������������������������� 51 Solution ��������������������������������������������������������������������������������������������������������������������������������� 51 Discussion ����������������������������������������������������������������������������������������������������������������������������� 52 Assembling a Grand Combination ����������������������������������������������������������������������������������������������� 52 Task ��������������������������������������������������������������������������������������������������������������������������������������� 53 Table of ConTenTs
📄 Page 8
viii Solution ��������������������������������������������������������������������������������������������������������������������������������� 53 Discussion ����������������������������������������������������������������������������������������������������������������������������� 54 Working with Decimal Numbers ������������������������������������������������������������������������������������������������� 54 Task ��������������������������������������������������������������������������������������������������������������������������������������� 54 Solution ��������������������������������������������������������������������������������������������������������������������������������� 54 Discussion ����������������������������������������������������������������������������������������������������������������������������� 55 Working with Logical Values ������������������������������������������������������������������������������������������������������� 56 Task ��������������������������������������������������������������������������������������������������������������������������������������� 56 Solution ��������������������������������������������������������������������������������������������������������������������������������� 56 Discussion ����������������������������������������������������������������������������������������������������������������������������� 56 Summary������������������������������������������������������������������������������������������������������������������������������������� 57 Chapter 5: Working with Objects ���������������������������������������������������������������������������� 59 What Time Is It? �������������������������������������������������������������������������������������������������������������������������� 59 Task ��������������������������������������������������������������������������������������������������������������������������������������� 59 Solution ��������������������������������������������������������������������������������������������������������������������������������� 60 What Date Is It Today? ����������������������������������������������������������������������������������������������������������������� 60 Task ��������������������������������������������������������������������������������������������������������������������������������������� 60 Solution ��������������������������������������������������������������������������������������������������������������������������������� 61 Working with Date Components �������������������������������������������������������������������������������������������������� 62 Task ��������������������������������������������������������������������������������������������������������������������������������������� 62 Solution ��������������������������������������������������������������������������������������������������������������������������������� 62 Using Namespaces ��������������������������������������������������������������������������������������������������������������������� 63 Important using ��������������������������������������������������������������������������������������������������������������������� 63 Namespaces �������������������������������������������������������������������������������������������������������������������������� 65 Without usings ����������������������������������������������������������������������������������������������������������������������� 66 C# 9�0 Minimalistic Program ������������������������������������������������������������������������������������������������������� 67 Using the Environment Object ����������������������������������������������������������������������������������������������������� 70 Task ��������������������������������������������������������������������������������������������������������������������������������������� 70 Solution ��������������������������������������������������������������������������������������������������������������������������������� 70 Summary������������������������������������������������������������������������������������������������������������������������������������� 71 Table of ConTenTs
📄 Page 9
ix Chapter 6: Using Object Actions ����������������������������������������������������������������������������� 73 Displaying the Month in Text ������������������������������������������������������������������������������������������������������� 73 Task ��������������������������������������������������������������������������������������������������������������������������������������� 73 Solution ��������������������������������������������������������������������������������������������������������������������������������� 74 Discussion ����������������������������������������������������������������������������������������������������������������������������� 74 Displaying Tomorrow ������������������������������������������������������������������������������������������������������������������� 74 Task ��������������������������������������������������������������������������������������������������������������������������������������� 75 Solution ��������������������������������������������������������������������������������������������������������������������������������� 75 Displaying a Specific Date ���������������������������������������������������������������������������������������������������������� 76 Task ��������������������������������������������������������������������������������������������������������������������������������������� 76 Solution ��������������������������������������������������������������������������������������������������������������������������������� 76 Rolling a Single Die ��������������������������������������������������������������������������������������������������������������������� 77 Task ��������������������������������������������������������������������������������������������������������������������������������������� 77 Solution ��������������������������������������������������������������������������������������������������������������������������������� 77 Note ��������������������������������������������������������������������������������������������������������������������������������������� 78 Rolling Two Dice �������������������������������������������������������������������������������������������������������������������������� 78 Task ��������������������������������������������������������������������������������������������������������������������������������������� 78 Solution ��������������������������������������������������������������������������������������������������������������������������������� 79 Getting the Path to the Desktop �������������������������������������������������������������������������������������������������� 80 Task ��������������������������������������������������������������������������������������������������������������������������������������� 81 Solution ��������������������������������������������������������������������������������������������������������������������������������� 81 Enumeration �������������������������������������������������������������������������������������������������������������������������� 82 Summary������������������������������������������������������������������������������������������������������������������������������������� 83 Chapter 7: More About Objects ������������������������������������������������������������������������������� 85 Text as an Object ������������������������������������������������������������������������������������������������������������������������� 85 Task ��������������������������������������������������������������������������������������������������������������������������������������� 85 Solution ��������������������������������������������������������������������������������������������������������������������������������� 86 Discussion ����������������������������������������������������������������������������������������������������������������������������� 86 Table of ConTenTs
📄 Page 10
x Numbers as Objects �������������������������������������������������������������������������������������������������������������������� 87 Task ��������������������������������������������������������������������������������������������������������������������������������������� 87 Solution ��������������������������������������������������������������������������������������������������������������������������������� 88 Discussion ����������������������������������������������������������������������������������������������������������������������������� 88 Formatting Numbers ������������������������������������������������������������������������������������������������������������������� 89 Task ��������������������������������������������������������������������������������������������������������������������������������������� 90 Solution ��������������������������������������������������������������������������������������������������������������������������������� 90 Localized Output ������������������������������������������������������������������������������������������������������������������������� 91 Task ��������������������������������������������������������������������������������������������������������������������������������������� 91 Solution ��������������������������������������������������������������������������������������������������������������������������������� 92 Concluding Notes ������������������������������������������������������������������������������������������������������������������������ 93 Static Objects ������������������������������������������������������������������������������������������������������������������������ 93 Classes ���������������������������������������������������������������������������������������������������������������������������������� 94 Relation Between Class and Object ��������������������������������������������������������������������������������������� 94 Special Classes ��������������������������������������������������������������������������������������������������������������������� 94 Structures ������������������������������������������������������������������������������������������������������������������������������ 95 Summary������������������������������������������������������������������������������������������������������������������������������������� 95 Part II: Calculations �������������������������������������������������������������������������������������� 97 Chapter 8: Input ������������������������������������������������������������������������������������������������������ 99 Text Input ������������������������������������������������������������������������������������������������������������������������������������ 99 Task ��������������������������������������������������������������������������������������������������������������������������������������� 99 Solution ������������������������������������������������������������������������������������������������������������������������������� 100 Better Input ������������������������������������������������������������������������������������������������������������������������������� 100 Task ������������������������������������������������������������������������������������������������������������������������������������� 100 Solution ������������������������������������������������������������������������������������������������������������������������������� 101 Discussion ��������������������������������������������������������������������������������������������������������������������������� 101 Numeric Input ��������������������������������������������������������������������������������������������������������������������������� 101 Task ������������������������������������������������������������������������������������������������������������������������������������� 101 Solution ������������������������������������������������������������������������������������������������������������������������������� 102 Discussion ��������������������������������������������������������������������������������������������������������������������������� 103 Table of ConTenTs
📄 Page 11
xi Calculation with Entered Number ��������������������������������������������������������������������������������������������� 103 Task ������������������������������������������������������������������������������������������������������������������������������������� 103 Solution ������������������������������������������������������������������������������������������������������������������������������� 104 Ten More ����������������������������������������������������������������������������������������������������������������������������������� 104 Task ������������������������������������������������������������������������������������������������������������������������������������� 104 Solution ������������������������������������������������������������������������������������������������������������������������������� 105 Addition ������������������������������������������������������������������������������������������������������������������������������������� 105 Task ������������������������������������������������������������������������������������������������������������������������������������� 106 Solution ������������������������������������������������������������������������������������������������������������������������������� 106 Incorrect Input ��������������������������������������������������������������������������������������������������������������������������� 107 Task ������������������������������������������������������������������������������������������������������������������������������������� 107 Solution ������������������������������������������������������������������������������������������������������������������������������� 107 What Happened ������������������������������������������������������������������������������������������������������������������� 109 Interior of the catch Part������������������������������������������������������������������������������������������������������ 109 Complete Solution ��������������������������������������������������������������������������������������������������������������� 109 Testing ��������������������������������������������������������������������������������������������������������������������������������� 110 Explanation �������������������������������������������������������������������������������������������������������������������������� 110 Summary����������������������������������������������������������������������������������������������������������������������������������� 111 Chapter 9: Numbers ���������������������������������������������������������������������������������������������� 113 Decimal Input ���������������������������������������������������������������������������������������������������������������������������� 113 Task ������������������������������������������������������������������������������������������������������������������������������������� 113 Solution ������������������������������������������������������������������������������������������������������������������������������� 114 Localized Numeric Input ����������������������������������������������������������������������������������������������������������� 114 Task ������������������������������������������������������������������������������������������������������������������������������������� 115 Solution ������������������������������������������������������������������������������������������������������������������������������� 115 Testing and Conclusions ������������������������������������������������������������������������������������������������������ 116 Basic Arithmetic ������������������������������������������������������������������������������������������������������������������������ 118 Task ������������������������������������������������������������������������������������������������������������������������������������� 118 Solution ������������������������������������������������������������������������������������������������������������������������������� 118 Mathematical Functions������������������������������������������������������������������������������������������������������������ 119 Task ������������������������������������������������������������������������������������������������������������������������������������� 119 Table of ConTenTs
📄 Page 12
xii Solution ������������������������������������������������������������������������������������������������������������������������������� 120 Discussion ��������������������������������������������������������������������������������������������������������������������������� 121 Integer Division ������������������������������������������������������������������������������������������������������������������������� 121 Task ������������������������������������������������������������������������������������������������������������������������������������� 122 Solution ������������������������������������������������������������������������������������������������������������������������������� 123 Discussion ��������������������������������������������������������������������������������������������������������������������������� 124 Summary����������������������������������������������������������������������������������������������������������������������������������� 124 Chapter 10: Economic Calculations ���������������������������������������������������������������������� 127 Currency Conversion ����������������������������������������������������������������������������������������������������������������� 127 Task ������������������������������������������������������������������������������������������������������������������������������������� 127 Solution ������������������������������������������������������������������������������������������������������������������������������� 128 Total Price ��������������������������������������������������������������������������������������������������������������������������������� 128 Task ������������������������������������������������������������������������������������������������������������������������������������� 128 Solution ������������������������������������������������������������������������������������������������������������������������������� 129 Discussion ��������������������������������������������������������������������������������������������������������������������������� 130 Commissions ����������������������������������������������������������������������������������������������������������������������������� 130 Task ������������������������������������������������������������������������������������������������������������������������������������� 131 Solution ������������������������������������������������������������������������������������������������������������������������������� 131 Discussion ��������������������������������������������������������������������������������������������������������������������������� 132 Rounding ����������������������������������������������������������������������������������������������������������������������������������� 133 Task ������������������������������������������������������������������������������������������������������������������������������������� 133 Solution ������������������������������������������������������������������������������������������������������������������������������� 134 Further Rounding ���������������������������������������������������������������������������������������������������������������������� 135 Task ������������������������������������������������������������������������������������������������������������������������������������� 135 Solution ������������������������������������������������������������������������������������������������������������������������������� 137 Value-Added Tax ����������������������������������������������������������������������������������������������������������������������� 139 Task ������������������������������������������������������������������������������������������������������������������������������������� 139 Analysis ������������������������������������������������������������������������������������������������������������������������������� 139 Solution ������������������������������������������������������������������������������������������������������������������������������� 140 Summary����������������������������������������������������������������������������������������������������������������������������������� 141 Table of ConTenTs
📄 Page 13
xiii Chapter 11: Calculations with Dates �������������������������������������������������������������������� 143 Date Input���������������������������������������������������������������������������������������������������������������������������������� 143 Task ������������������������������������������������������������������������������������������������������������������������������������� 143 Solution ������������������������������������������������������������������������������������������������������������������������������� 144 Discussion ��������������������������������������������������������������������������������������������������������������������������� 145 Single Month ����������������������������������������������������������������������������������������������������������������������������� 145 Task ������������������������������������������������������������������������������������������������������������������������������������� 145 Solution ������������������������������������������������������������������������������������������������������������������������������� 145 Discussion ��������������������������������������������������������������������������������������������������������������������������� 146 Quarter �������������������������������������������������������������������������������������������������������������������������������������� 147 Task ������������������������������������������������������������������������������������������������������������������������������������� 147 Analysis ������������������������������������������������������������������������������������������������������������������������������� 148 Solution ������������������������������������������������������������������������������������������������������������������������������� 149 Date Difference ������������������������������������������������������������������������������������������������������������������������� 149 Task ������������������������������������������������������������������������������������������������������������������������������������� 150 Solution ������������������������������������������������������������������������������������������������������������������������������� 150 Time Zones and UTC ����������������������������������������������������������������������������������������������������������������� 151 Task ������������������������������������������������������������������������������������������������������������������������������������� 151 Solution ������������������������������������������������������������������������������������������������������������������������������� 152 Summary����������������������������������������������������������������������������������������������������������������������������������� 153 Chapter 12: Understanding Different Kinds of Numbers ��������������������������������������� 155 More Numeric Types ����������������������������������������������������������������������������������������������������������������� 155 Task ������������������������������������������������������������������������������������������������������������������������������������� 155 Solution ������������������������������������������������������������������������������������������������������������������������������� 156 Discussion ��������������������������������������������������������������������������������������������������������������������������� 157 Memory Consumption ��������������������������������������������������������������������������������������������������������������� 159 Task ������������������������������������������������������������������������������������������������������������������������������������� 159 Solution ������������������������������������������������������������������������������������������������������������������������������� 160 Connections ������������������������������������������������������������������������������������������������������������������������� 160 Discussion ��������������������������������������������������������������������������������������������������������������������������� 161 Table of ConTenTs
📄 Page 14
xiv Overflow ������������������������������������������������������������������������������������������������������������������������������������ 161 Task ������������������������������������������������������������������������������������������������������������������������������������� 162 Solution ������������������������������������������������������������������������������������������������������������������������������� 162 Discussion ��������������������������������������������������������������������������������������������������������������������������� 163 Dealing with Overflow ��������������������������������������������������������������������������������������������������������������� 163 Task ������������������������������������������������������������������������������������������������������������������������������������� 163 Solution ������������������������������������������������������������������������������������������������������������������������������� 164 Settings in Visual Studio ������������������������������������������������������������������������������������������������������ 165 Results ��������������������������������������������������������������������������������������������������������������������������������� 167 Summary����������������������������������������������������������������������������������������������������������������������������������� 168 Chapter 13: Accumulating Values ������������������������������������������������������������������������ 171 Ten More, Revisited ������������������������������������������������������������������������������������������������������������������� 171 Task ������������������������������������������������������������������������������������������������������������������������������������� 172 Solution ������������������������������������������������������������������������������������������������������������������������������� 172 Discussion ��������������������������������������������������������������������������������������������������������������������������� 172 Compound Assignment ������������������������������������������������������������������������������������������������������������� 173 Task ������������������������������������������������������������������������������������������������������������������������������������� 173 Solution ������������������������������������������������������������������������������������������������������������������������������� 173 Further Compound Assignments ����������������������������������������������������������������������������������������������� 174 Task ������������������������������������������������������������������������������������������������������������������������������������� 174 Solution ������������������������������������������������������������������������������������������������������������������������������� 174 Incrementing and Decrementing ���������������������������������������������������������������������������������������������� 175 Task ������������������������������������������������������������������������������������������������������������������������������������� 175 Solution ������������������������������������������������������������������������������������������������������������������������������� 176 Compound Assignment and Text ����������������������������������������������������������������������������������������������� 177 Task ������������������������������������������������������������������������������������������������������������������������������������� 177 Solution ������������������������������������������������������������������������������������������������������������������������������� 177 Progressive Summation ������������������������������������������������������������������������������������������������������������ 178 Task ������������������������������������������������������������������������������������������������������������������������������������� 178 Solution ������������������������������������������������������������������������������������������������������������������������������� 179 Table of ConTenTs
📄 Page 15
xv Multiple Text Join ���������������������������������������������������������������������������������������������������������������������� 180 Task ������������������������������������������������������������������������������������������������������������������������������������� 180 Solution ������������������������������������������������������������������������������������������������������������������������������� 181 Summary����������������������������������������������������������������������������������������������������������������������������������� 182 Part III: Conditionals ����������������������������������������������������������������������������������� 183 Chapter 14: Essential Tools ���������������������������������������������������������������������������������� 185 IntelliSense ������������������������������������������������������������������������������������������������������������������������������� 185 Exploring the Possibilities ��������������������������������������������������������������������������������������������������� 185 Examples ����������������������������������������������������������������������������������������������������������������������������� 186 Note ������������������������������������������������������������������������������������������������������������������������������������� 189 Keyboard Shortcuts ������������������������������������������������������������������������������������������������������������� 189 Documentation �������������������������������������������������������������������������������������������������������������������������� 190 docs�microsoft�com ������������������������������������������������������������������������������������������������������������� 190 Search ��������������������������������������������������������������������������������������������������������������������������������� 191 Specific Class Page ������������������������������������������������������������������������������������������������������������� 192 Common Search ������������������������������������������������������������������������������������������������������������������ 194 Debugging Tools ������������������������������������������������������������������������������������������������������������������������ 195 Project ��������������������������������������������������������������������������������������������������������������������������������� 195 Stepping Through the Code ������������������������������������������������������������������������������������������������� 195 Breakpoints ������������������������������������������������������������������������������������������������������������������������� 197 Memory Inspection �������������������������������������������������������������������������������������������������������������� 198 C# Interactive ���������������������������������������������������������������������������������������������������������������������������� 200 What Is It? ���������������������������������������������������������������������������������������������������������������������������� 201 How to Launch It? ���������������������������������������������������������������������������������������������������������������� 201 Notes ����������������������������������������������������������������������������������������������������������������������������������� 202 Summary����������������������������������������������������������������������������������������������������������������������������������� 203 Chapter 15: Getting Started with Conditions �������������������������������������������������������� 205 Password Input ������������������������������������������������������������������������������������������������������������������������� 205 Task ������������������������������������������������������������������������������������������������������������������������������������� 205 Analysis ������������������������������������������������������������������������������������������������������������������������������� 206 Table of ConTenTs
📄 Page 16
xvi Solution ������������������������������������������������������������������������������������������������������������������������������� 208 Discussion ��������������������������������������������������������������������������������������������������������������������������� 209 Reversed Condition ������������������������������������������������������������������������������������������������������������������� 209 Task ������������������������������������������������������������������������������������������������������������������������������������� 209 Solution ������������������������������������������������������������������������������������������������������������������������������� 209 Discussion ��������������������������������������������������������������������������������������������������������������������������� 210 Length Check ���������������������������������������������������������������������������������������������������������������������������� 210 Task ������������������������������������������������������������������������������������������������������������������������������������� 210 Solution ������������������������������������������������������������������������������������������������������������������������������� 211 Positive Numbers ���������������������������������������������������������������������������������������������������������������������� 212 Task ������������������������������������������������������������������������������������������������������������������������������������� 212 Solution ������������������������������������������������������������������������������������������������������������������������������� 213 Odd and Even Numbers ������������������������������������������������������������������������������������������������������������ 215 Task ������������������������������������������������������������������������������������������������������������������������������������� 215 Solution ������������������������������������������������������������������������������������������������������������������������������� 216 Case Indifference ���������������������������������������������������������������������������������������������������������������������� 216 Task ������������������������������������������������������������������������������������������������������������������������������������� 217 Solution ������������������������������������������������������������������������������������������������������������������������������� 217 Without Braces �������������������������������������������������������������������������������������������������������������������������� 218 Task ������������������������������������������������������������������������������������������������������������������������������������� 219 Solution ������������������������������������������������������������������������������������������������������������������������������� 219 Greater of Two Numbers ����������������������������������������������������������������������������������������������������������� 219 Task ������������������������������������������������������������������������������������������������������������������������������������� 220 Solution ������������������������������������������������������������������������������������������������������������������������������� 220 Without the else Branch ������������������������������������������������������������������������������������������������������������ 221 Task ������������������������������������������������������������������������������������������������������������������������������������� 221 Solution ������������������������������������������������������������������������������������������������������������������������������� 222 Using a Built-in Function ����������������������������������������������������������������������������������������������������������� 222 Task ������������������������������������������������������������������������������������������������������������������������������������� 223 Solution ������������������������������������������������������������������������������������������������������������������������������� 223 Summary����������������������������������������������������������������������������������������������������������������������������������� 223 Table of ConTenTs
📄 Page 17
xvii Chapter 16: Practical Conditions �������������������������������������������������������������������������� 225 Appending Extension ���������������������������������������������������������������������������������������������������������������� 225 Task ������������������������������������������������������������������������������������������������������������������������������������� 225 Solution ������������������������������������������������������������������������������������������������������������������������������� 226 Discussion ��������������������������������������������������������������������������������������������������������������������������� 226 Head and Tail ����������������������������������������������������������������������������������������������������������������������������� 228 Task ������������������������������������������������������������������������������������������������������������������������������������� 228 Solution ������������������������������������������������������������������������������������������������������������������������������� 228 Deadline Check ������������������������������������������������������������������������������������������������������������������������� 229 Task ������������������������������������������������������������������������������������������������������������������������������������� 229 Solution ������������������������������������������������������������������������������������������������������������������������������� 230 Invoice Date Check ������������������������������������������������������������������������������������������������������������������� 231 Task ������������������������������������������������������������������������������������������������������������������������������������� 231 Solution ������������������������������������������������������������������������������������������������������������������������������� 232 Spanish Day of Week ���������������������������������������������������������������������������������������������������������������� 233 Task ������������������������������������������������������������������������������������������������������������������������������������� 233 Solution ������������������������������������������������������������������������������������������������������������������������������� 234 Switch Statement ��������������������������������������������������������������������������������������������������������������������� 236 Task ������������������������������������������������������������������������������������������������������������������������������������� 236 Solution ������������������������������������������������������������������������������������������������������������������������������� 236 Summary����������������������������������������������������������������������������������������������������������������������������������� 238 Chapter 17: Compound Conditions ����������������������������������������������������������������������� 239 Yes or No ����������������������������������������������������������������������������������������������������������������������������������� 239 Task ������������������������������������������������������������������������������������������������������������������������������������� 239 Solution ������������������������������������������������������������������������������������������������������������������������������� 240 Discussion ��������������������������������������������������������������������������������������������������������������������������� 241 Username and Password ���������������������������������������������������������������������������������������������������������� 241 Task ������������������������������������������������������������������������������������������������������������������������������������� 241 Solution ������������������������������������������������������������������������������������������������������������������������������� 242 Discussion ��������������������������������������������������������������������������������������������������������������������������� 243 Table of ConTenTs
📄 Page 18
xviii Two Users���������������������������������������������������������������������������������������������������������������������������������� 243 Task ������������������������������������������������������������������������������������������������������������������������������������� 244 Solution ������������������������������������������������������������������������������������������������������������������������������� 244 Discussion ��������������������������������������������������������������������������������������������������������������������������� 245 Precalculation of Conditions ����������������������������������������������������������������������������������������������������� 245 Task ������������������������������������������������������������������������������������������������������������������������������������� 245 Solution ������������������������������������������������������������������������������������������������������������������������������� 246 Discussion ��������������������������������������������������������������������������������������������������������������������������� 247 Yes or No Reversed ������������������������������������������������������������������������������������������������������������������� 247 Task ������������������������������������������������������������������������������������������������������������������������������������� 247 Solution ������������������������������������������������������������������������������������������������������������������������������� 247 Discussion ��������������������������������������������������������������������������������������������������������������������������� 248 Grade Check ������������������������������������������������������������������������������������������������������������������������������ 248 Task ������������������������������������������������������������������������������������������������������������������������������������� 248 Solution ������������������������������������������������������������������������������������������������������������������������������� 249 Better Range Check ������������������������������������������������������������������������������������������������������������������ 250 Task ������������������������������������������������������������������������������������������������������������������������������������� 250 Solution ������������������������������������������������������������������������������������������������������������������������������� 250 Summary����������������������������������������������������������������������������������������������������������������������������������� 251 Chapter 18: Multiple Conditions ��������������������������������������������������������������������������� 253 Soccer ��������������������������������������������������������������������������������������������������������������������������������������� 253 Task ������������������������������������������������������������������������������������������������������������������������������������� 253 Analysis ������������������������������������������������������������������������������������������������������������������������������� 254 Solution ������������������������������������������������������������������������������������������������������������������������������� 256 Soccer Alternatively ������������������������������������������������������������������������������������������������������������������ 257 Analysis ������������������������������������������������������������������������������������������������������������������������������� 257 Solution ������������������������������������������������������������������������������������������������������������������������������� 258 Minimum of Three Numbers ����������������������������������������������������������������������������������������������������� 259 Task ������������������������������������������������������������������������������������������������������������������������������������� 259 Analysis ������������������������������������������������������������������������������������������������������������������������������� 259 Solution ������������������������������������������������������������������������������������������������������������������������������� 260 Table of ConTenTs
📄 Page 19
xix Minimum with Built-in Function������������������������������������������������������������������������������������������������ 261 Solution ������������������������������������������������������������������������������������������������������������������������������� 261 Linear Equation ������������������������������������������������������������������������������������������������������������������������� 262 Task ������������������������������������������������������������������������������������������������������������������������������������� 262 Analysis ������������������������������������������������������������������������������������������������������������������������������� 262 Solution ������������������������������������������������������������������������������������������������������������������������������� 263 Quadratic Equation �������������������������������������������������������������������������������������������������������������������� 264 Task ������������������������������������������������������������������������������������������������������������������������������������� 264 Analysis ������������������������������������������������������������������������������������������������������������������������������� 265 Solution ������������������������������������������������������������������������������������������������������������������������������� 266 Discussion ��������������������������������������������������������������������������������������������������������������������������� 267 Summary����������������������������������������������������������������������������������������������������������������������������������� 267 Chapter 19: Advanced Conditions������������������������������������������������������������������������� 269 Conditional Operator ����������������������������������������������������������������������������������������������������������������� 269 Task ������������������������������������������������������������������������������������������������������������������������������������� 269 Solution ������������������������������������������������������������������������������������������������������������������������������� 270 Discussion ��������������������������������������������������������������������������������������������������������������������������� 270 Summary Evaluation ����������������������������������������������������������������������������������������������������������������� 271 Task ������������������������������������������������������������������������������������������������������������������������������������� 271 Details ��������������������������������������������������������������������������������������������������������������������������������� 271 Solution ������������������������������������������������������������������������������������������������������������������������������� 272 Discussion ��������������������������������������������������������������������������������������������������������������������������� 275 Second Character Test �������������������������������������������������������������������������������������������������������������� 276 Task ������������������������������������������������������������������������������������������������������������������������������������� 276 Solution ������������������������������������������������������������������������������������������������������������������������������� 278 Discussion ��������������������������������������������������������������������������������������������������������������������������� 278 Summary����������������������������������������������������������������������������������������������������������������������������������� 280 Table of ConTenTs
📄 Page 20
xx Part IV: Loops���������������������������������������������������������������������������������������������� 281 Chapter 20: First Loops ���������������������������������������������������������������������������������������� 283 Repeating the Same Text ���������������������������������������������������������������������������������������������������������� 283 Task ������������������������������������������������������������������������������������������������������������������������������������� 283 Solution ������������������������������������������������������������������������������������������������������������������������������� 284 Solution Using a Loop ���������������������������������������������������������������������������������������������������������� 285 Solution ������������������������������������������������������������������������������������������������������������������������������� 285 How the for Loop Works ������������������������������������������������������������������������������������������������������ 285 The Loop ������������������������������������������������������������������������������������������������������������������������������ 287 Explore It Yourself ���������������������������������������������������������������������������������������������������������������� 287 Tip ���������������������������������������������������������������������������������������������������������������������������������������� 287 Choosing the Number of Repetitions ���������������������������������������������������������������������������������������� 287 Task ������������������������������������������������������������������������������������������������������������������������������������� 287 Solution ������������������������������������������������������������������������������������������������������������������������������� 288 Discussion ��������������������������������������������������������������������������������������������������������������������������� 289 Throwing a Die Repeatedly ������������������������������������������������������������������������������������������������������� 289 Task ������������������������������������������������������������������������������������������������������������������������������������� 289 Solution ������������������������������������������������������������������������������������������������������������������������������� 290 Repeating Similar Lines ������������������������������������������������������������������������������������������������������������ 290 Task ������������������������������������������������������������������������������������������������������������������������������������� 290 Solution Without a Loop ������������������������������������������������������������������������������������������������������� 291 Solution Using a Loop ���������������������������������������������������������������������������������������������������������� 292 Discussion ��������������������������������������������������������������������������������������������������������������������������� 292 Summary����������������������������������������������������������������������������������������������������������������������������������� 293 Chapter 21: Improving Loops ������������������������������������������������������������������������������� 295 Choosing Text ���������������������������������������������������������������������������������������������������������������������������� 295 Task ������������������������������������������������������������������������������������������������������������������������������������� 295 Solution ������������������������������������������������������������������������������������������������������������������������������� 296 Alternating Loop ������������������������������������������������������������������������������������������������������������������������ 296 Task ������������������������������������������������������������������������������������������������������������������������������������� 296 Table of ConTenTs
The above is a preview of the first 20 pages. Register to read the complete e-book.

💝 Support Author

0.00
Total Amount (¥)
0
Donation Count

Login to support the author

Login Now

Recommended for You

Loading recommended books...
Failed to load, please try again later
Back to List