BEGINNING
C# 7 Programming
with Visual Studio
®
2017
Benjamin Perkins
Jacob Vibe Hammer
Jon D. Reid
Beginning C# 7 Programming with Visual Studio
®
2017
Published by
John Wiley & Sons, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2018 by John Wiley & Sons, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-1-119-45868-5
ISBN: 978-1-119-45872-2 (ebk)
ISBN: 978-1-119-45866-1 (ebk)
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means,
electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108
of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization
through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers,
MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the
Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201)
748-6008, or online at
http://www.wiley.com/go/permissions.
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with
respect to the accuracy or completeness of the contents of this work and specically disclaim all warranties, including
without limitation warranties of tness for a particular purpose. No warranty may be created or extended by sales or pro-
motional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold
with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services.
If professional assistance is required, the services of a competent professional person should be sought. Neither the pub-
lisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to
in this work as a citation and/or a potential source of further information does not mean that the author or the publisher
endorses the information the organization or Web site may provide or recommendations it may make. Further, readers
should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was
written and when it is read.
For general information on our other products and services please contact our Customer Care Department within the
United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with stan-
dard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such
as a CD or DVD that is not included in the version you purchased, you may download this material at http://
booksupport.wiley.com
. For more information about Wiley products, visit www.wiley.com.
Library of Congress Control Number: 2018933383
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trade-
marks or registered trademarks of John Wiley & Sons, Inc. and/or its afliates, in the United States and other countries,
and may not be used without written permission. Visual Studio is a registered trademark of Microsoft Corporation. All
other trademarks are the property of their respective owners. John Wiley & Sons, Inc., is not associated with any product
or vendor mentioned in this book.
ABOUT THE AUTHORS
BENJAMIN PERKINS (MBA, MCSD, ITIL) is currently employed at Microsoft in Munich, Germany,
as a Senior Escalation Engineer. He has been working professionally in the IT industry for over two
decades. He started computer programming with QBasic at the age of 11 on an Atari 1200XL desk-
top computer. He takes pleasure in the challenges that troubleshooting technical issues has to offer
and savors the rewards of a well-written program. After completing high school he joined the United
States Army. After successfully completing his military service, he attended Texas A&M University
in College Station, Texas, where he received a Bachelor of Business Administration in Management
Information Systems.
His roles in the IT industry have spanned the entire spectrum including programmer, system
architect, technical support engineer, team leader, and mid-level management. While employed at
Hewlett-Packard, he received numerous awards, degrees, and certications. He has a passion for
technology and customer service and looks forward to troubleshooting and writing more world-
class technical solutions.
“My approach is to write code with support in mind, and to write it once correctly and completely
so we do not have to come back to it again, except to enhance it.”
Benjamin is married to Andrea and has two wonderful children, Lea and Noa.
JACOB VIBE HAMMER helps develop solutions for the health care industry as a Senior Software
Engineer at Systematic in Denmark. He started programming just about the time when he was able
to spell the word “BASIC”—which, incidentally, is the rst programming language he ever used.
Since then, he has worked with numerous programming languages and solution architectures;
however, since the turn of the century, he has worked primarily with the .NET platform. Today,
his programming time is spent working primarily with C# and WPF, as well as toying with NoSQL
databases. A Danish citizen, Jacob lives in Aarhus, Denmark, with his wife and two sons.
JON D. REID is a Product Solution Manager for IFS Field Service Management (www.IFSWORLD
.com
). He has coauthored a number of books, including Beginning Visual C# 2015, Fast Track C#,
Pro Visual Studio .NET, and many others.
ABOUT THE TECHNICAL EDITOR
JOHN MUELLER is a freelance author and technical editor. He has writing in his blood, having pro-
duced 108 books and more than 600 articles to date. The topics range from networking to articial
intelligence and from database management to heads-down programming. Some of his current
books include topics such as Python for beginners, Python for data scientists, and Amazon Web
Services. He has also written about algorithms and machine learning. His technical editing skills
have helped more than 70 authors rene the content of their manuscripts. John has provided
technical editing services to a number of computing magazines. Be sure to read John’s blog at
http://blog.johnmuellerbooks.com/.
SENIOR ACQUISITIONS EDITOR
Kenyon Brown
PROJECT EDITOR
Tom Dinse
TECHNICAL EDITOR
John Mueller
PRODUCTION EDITOR
Barath Kumar Rajasekaran
COPY EDITOR
First Edition Publishing Services
PRODUCTION MANAGER
Katie Wisor
MANAGER OF CONTENT ENABLEMENT
AND OPERATIONS
Pete Gaughan
MARKETING MANAGER
Christie Hilbrich
BUSINESS MANAGER
Amy Knies
PROJECT COORDINATOR, COVER
Brent Savage
PROOFREADER
Nancy Bell
INDEXER
Johnna VanHoose Dinse
COVER DESIGNER
Wiley
COVER IMAGE
©Ben Clift Williams/EyeEm/Getty Images
CREDITS