The Beginner's Guide to C# | Eric Frick | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

The Beginner's Guide to C#

teacher avatar Eric Frick, Destin Learning

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

25 Lessons (2h 48m)
    • 1. Class Promo

      3:40
    • 2. Chapter 1 Introduction

      5:28
    • 3. Chapter 2 What is a Console Program?

      5:47
    • 4. Getting the Source Code for this Course

      5:10
    • 5. Chapter 3 Hello World Windows

      15:19
    • 6. Chapter 4 Hello World Google Cloud Platform

      11:38
    • 7. Chapter 5 Comments in C#

      8:50
    • 8. Chapter 6 Input Statements

      5:05
    • 9. Chapter 7 Methods

      11:18
    • 10. Chapter 8 If Statements

      7:08
    • 11. Chapter 9 Loops

      9:54
    • 12. Coding Exercise 1

      2:30
    • 13. Chapter 10 Data Types

      8:53
    • 14. Chapter 11 Exceptions

      6:11
    • 15. Chapter 12 Switch Statements

      5:33
    • 16. Chapter 13 Arrays

      9:34
    • 17. Coding Exercise 3

      1:39
    • 18. Chapter 15 Using Statements

      6:38
    • 19. Chapter 16 File Output

      8:11
    • 20. Chapter 17 File Input

      8:04
    • 21. Chapter 18 Strings and Functions

      8:13
    • 22. Coding Exercise 3

      1:39
    • 23. Chapter 19 Dates and Functions

      8:58
    • 24. Coding Exercise 4

      2:06
    • 25. Class Summary

      0:54
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

30

Students

--

Projects

About This Class

The C# programming language from Microsoft is one of the most popular programming languages in the world. This class is designed for an absolute beginner to get started with this powerful programming language. You do not need any prior programming experience to read this book. You will need access to a PC to install .NET Core (free download) to run the labs in this class. I will also show you some affordable cloud-based options so you can do your software development in the cloud. In this class, I will start with a very basic sample program and then we will add elements that illustrate basic language constructs step by step to this program until you have a complete demonstration program. We will review basic language elements such as:

  • Loops
  • If Statements
  • Case statements
  • C# Data Types
  • Methods
  • Object-Oriented Programming and
  • More

After that, we will then build a more complete demonstration program that integrates all of the concepts in the class. By the end of this class, you will have a basic knowledge of the C# programming language and will be able to write your own programs. Included with this class is a downloadable ebook that contains detailed instructions for each of the lessons in this class.

Meet Your Teacher

Teacher Profile Image

Eric Frick

Destin Learning

Teacher

I have been involved in software development and IT operations for 30 years. I have worked as a Software Developer, Software Development Manager, Software Architect and as an Operations Manager. In addition for the last five years have taught evening classes in various IT related subjects at a local university. I am developing a series of online classes that can provide practical information to students on various IT related topics. I have started an on-online education site Destin Learning and work as a full-time content author for Linux Academy teaching certification classes for the Google Cloud Platform.

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Class Promo: Yeah. Hello, everyone. Welcome to the Beginner's Guide to see Sharp. In this course, I'll teach you the fundamentals of one of the most important programming languages in the world. See Sharp from Microsoft. Hello, everyone. My name is Eric Frick and I'll be your instructor for this course. I've had over 30 years of I t. Experience as a programmer, a software development manager and I t architect and finally as a. I T executive. So I have a lot of experience I can draw from that I've put into this course. In addition, I have over 10 years of experience in teaching both on premise and online, and I've taught subjects is cloud computing database management systems, mobile application development. And most of all, I've taught a lot of software development courses, and that's my true joys to to teach software development courses. So let's go ahead and take a look at what we're gonna cover in this course. So first off, welcome to the class. This class assumes you have no prior programming experience. It's really intended for entry level developers and to learn to program, you have to practice. And so I've included a lot of practice exercises in this course, so we're going to start by building a demonstration program and then we're gonna keep adding features to it. This is a console program, and it's a great place to start any programming language, and I'm going to show you how to do it in C sharp. So that way we can concentrate on the basics and the constructs of the language and not have to worry about a lot of other details. So at the end of this class, you're gonna have a complete demonstration program that outlines all the major features of C sharp. I'm gonna offer you two different development environments that you can use first, all outline a development environment where you could use the Google Cloud platform. Sign up for a free account and you can develop your code up there. And all the tools are already there in place. If you want to learn a little bit about the cloud, this is a great place to develop. Quetta. The section up second option is to download install the dot net core platform and visual studio code. Both of these are free downloads. And what's great about this? Is there available for Mac Windows and Linux. So whatever desktop environment you have, visual studio code and dot net core can work for you. I've included PdF files in this course, so every lesson has a PdF file that you can work through the exercises. So as I show you how to build the demo program, you could do it on your own and reinforce that knowledge and really build on up those hands on programming skills and really learn the C sharp language, the elements that we're going to cover in this class from first, I'll show you how to do your development environment that will show you bit by bit elements of the language when we'll introduce them just a little bit at a time. So we'll look start by looking at Hello World, our first program. Then we'll look at input statements and methods. Also, look at control statements, things like if statements loops, basic data types, arrays that air containers for variables and then we'll look at how the handle errors with exceptions. Then we'll look Atmore control statements like switch statements and also take some time to show you some of the features of visual studio code to really help you along the way. We'll look at how use it, having using statements. Consider Cliff I your code and then we'll look at some really common scenarios across all programming languages will look at file output input, will look at strings and dates and how to handle those within C sharp. It finally will wrap up the class by looking at object oriented programming, also including a brief look at inheritance. So thank you so much. Thank you for your interest in this class. And I hope to see you in class soon. Thanks again. 2. Chapter 1 Introduction: Yeah. Hello, everyone. And welcome to the Beginner's Guide to See Sharp. My name is Eric Frick, and I'll be your instructor for this course. So let's go ahead and take a look at what we're going to cover in this course. So first off, welcome to the class. This class assumes you have no prior programming experience. It's really intended for entry level developers. If you're in experience dot Net or C Sharp Developer. This is probably not the course for you. So learning requires learning to program requires practice. And and I've included a lot of exercises in this course, and learning to program is a lot like a musical instrument. You really need to practice it a lot to get better at it. So let's go ahead and take a look at some of the details. As far as the class outline, we're gonna build a demo program. I'm gonna keep adding features to it bit by bit. So in each chapter we're gonna add more tar demonstration program. This burger is a consul program, which is a great place to start in any programming language, and I'll show you how to do it in C sharp we're gonna concentrate on the basics of the language and really what the fundamentals are of the constructs of the C sharp programming language and by using a console program that allows us to concentrate on doing just that. At the end of the class, you'll have a complete demo program that really highlights a number of the most important aspects of the C sharp programming language. As far as a development environment outlined to basic development environments that you can use for this course, the 1st 1 is to sign up for a free account on the Google Cloud Platform or G C. P. You get a $300 credit and you can develop your code up there dot net core is already installed, and there's a built in editor in the G C P environment. And there's no charge for using the development consul in G. C. P. So it's really if you're interested in learning a little bit about the cloud, it's a great way to develop in. Your code is automatically backed up so you don't have to worry about losing any code up there. The second option is to download install dot net core and visual studio code. Both of these air free downloads and the great thing about both of these is there available for Windows, Mac and Linux. So no matter what operating system you're running on your desktop or notebook computer, you can run it on any one of those environments. So those are the two major options. I personally used the cloud like to develop up there because it's a no hassle option, and all I need is a Web browser to get to it. But the choice is up to you. The demonstrations I'll show you, though, are off of Windows, but the code will be completely the same. No matter matter where he decided. Developed PDF files. I've included PdF lab files for each of the chapters, so the chapters will work. While I'll show the concept of a particular language construct, I'll demonstrate how to integrate that into your sample program. And then the PdF file is there for you to go ahead and complete the exercise on your own. So you'll be building this demo programme alongside with me step by step through the entire course. So the C sharp language elements were going to cover we're gonna show you first your development environment and whether you decide to do G c p or install it on your local machine, I'll show you how to install it on Windows. And then we're going to start looking at the aspects of the language and building out our demo programs. So we'll look first of a consul prayer. What really is a console program? And then the traditional program in any language of first program is hello world, and this will be no exception. So we'll do that. They were gonna look at some more of the details of the language itself. How you do comments, statements and see sharp how input is handled through input statements, how you can module, arise your code with methods and then we'll start looking. Construct the control structures if statements and loops next, we'll look at all the data types that are available in C sharp in some of the highlights of that, and then how to handle error conditions. With exceptions, next will move into a raise that you can have large collections of data and structure to raise, and then we'll look a switch statements another very flexible control statement. Then we'll look at a few options that are available to you in visual studio code. And then we're gonna look at more code aspects. We're gonna look at using statements and how you can simplify your code using using statements. And then we're gonna look at some really common functions. In all programming languages will look at file output input. Then we'll look at strings and functions and date and functions that finally will wrap up the course by looking at object oriented programming and inheritance. So again, we're going to create an example. Program will build on this chapter by chapter, and then we'll have a complete demo program at the end of the course. By the end of this class, you'll be familiar with most of the major constructs of the C sharp programming language. You'll be able to build your own consul programs and building compile code, and have included some additional exercises that will also reinforce, in addition to our demo program, what we're building. You'll be able to develop programs with dot net Core, which is Microsoft's open source cross platform framework, so you should be really ready to go. This is a build a solid baseline and C sharp. If you want to move on to more complex project, This is a perfect place to start. So I'm anxious to jump in and material thank you so much for signing up for this course. And I'll see you in the first lesson. Thanks again. 3. Chapter 2 What is a Console Program?: Hello, everyone In this chapter, we're gonna look at console programs. We're gonna be using consul programs extensively in this course. So let's go ahead and look and see what one is and how you can use it. So a console program is one of the simplest forms of programs. Its origins go back to the early M S DOS operating system. When that was the only way to interact with computer system, there was no Windows interface. It was only a command line, so there's no graphics about it. It's on Lee, a text base in her face, and one of its advantages is It's very simple. So let's look at a few more details. Most operating systems have a command line, so the DOS operating system are. Windows 10 still has a command line interface today, and we're going to take a look at it in just a minute, and you can write things that run in the in the console. In other languages other than C sharp, you can write something in python or Java or even an M s dusk script, for example. So there again, most operating systems, even Windows 10 still have it, and the output is consistent, it's easy to use, so it's ideal for a teaching environment. And that way you don't have to get concerned with a bunch of other things that get in the way. You can just concentrate on the language itself and learn it quickly. So let's go ahead and bring up Ah, demo of a consul and how you interact with a constant council and Windows 10 the basic navigation and how you run a program. So let's go ahead and jump over to the Windows machine and have a look. Okay, so here I am in my Windows 10 machine and we're gonna go ahead and start up the command line. So to do that, you can go into the search down in the lower left, and you can just type in CMD and notice how it brings up. Then the command prompt. If I double click on that, then it launches are command line interface or the command prompt. So some simple commands that you can use the 1st 1 is a directory command or D I R. And this will show you the contents of that particular directory so it gives you a directory listing. There are lots of options around the directory command. One of the things you can do to look at some of those options you can type in help de IR, and it will give you some of the basic information on how to use this. The main thing that you'll need to use in this course is to navigate to different directories. And to do that, you'll use the strange directory or CD command. So in our course, we're going to create a directory for all of our code. And we're gonna call it C s code and noticed if you look the files, air and directories are in alphabetical order, and then we CRCs code directory, which is analogous to a folder if you're using the Windows File Explorer. So to change my directory, Aiken type in CD or change directory to see s code CS coat Type that in, and you'll notice now that my prompt also changes. A swell on indicates that I'm now My default directory now is the C s code directory. I've started putting in some code in here and noticed that we have another directory or folder underneath here called ch four for Chapter four. If I want to change to that directory, I can type in CD two CH four and it will take me to that directory. So hearing him, um, will be creating this in a lesson down the road here. But this is our hello world program, and if I want to run this program, I can type in the command dot net run. I made a typo here, so let me go ahead and correct that dot net run, and it will go ahead and run that program. So there's different. There's different commands for different languages. If you're gonna compile a job a program, for example, you can compile at with the Java or J A V a C Command to compile something. There's different commands for python and other things, but this is the basics of how you can navigate if you want to change to a directory back to where you came from. And users slash Eric is my original directory. I can type in CD dot dot and it will take me up a level and cd dot dot once again will take me to that home level directory, which, in my case is slash users slash eric. So that's a quick thing about the command line, and that's really all you'll need for this course. There's one other command you're gonna need to copy a few programs, but I'm going to give the syntax to the to you to do that later on. That's really it. It's very simple to use the command line. There's tons of videos out on YouTube if you want to go into more detail about the command line, but I'll show you everything that you need to know as you go along step by step in these lessons. So let's go ahead and jump to the summary and wrap this lesson up In summary. We've looked at console programs, these air programs without a graphical user interface, and they could be created for almost any operating system in use today. So, for example, Windows Lennox, the Mac OS has ah terminal programas well, so most operating systems, particularly desktop operating systems, have a command line interface. They're typically very utilitarian. They're great for things that air routine tasks for things like back up or copying files, maintenance utilities. And they're also very good for learning a programming language because it really simplifies things that allows you to concentrate just on the language itself. So that's really it for this lesson. Thank you so much, and I'll see in the next lesson by 4. Getting the Source Code for this Course: Hello, everyone. In this lesson, I'm gonna show you how you can get the source code for this class. So I've put all the source code out there so that you can download it and get a copy of it . So that way, if you have any problems, you can look at my code versus your code. Copy and paste. Compare whatever. So let's go ahead and take a look at that. How you conduce that. So I've put all of the source code for this class and get hub and source. Code control is really one of the most important areas of software development. So if you don't know anything about get I highly recommend that you that you dio and also get Hub is free to use so you can sign up for a free account and put your own source code that there as you're building it, So that's a good thing to do with this class is go ahead and set up to get hub account. I won't cover how to do It's pretty straightforward again. It's free, and there are get clients for Windows, Macs and Lennox, and so you'll need to install one of those clients to get the source code, so get help for Windows. Um, there's a version for Windows, Mac and Lennox. I've put the you are else for all three of those out there. It's a pretty lightweight, easy insult, especially for Lennox. It's very straightforward with Lennox and ah, it's very easy to use. It's a command line driven system, and there's also a really good cheat sheet out on the get hub site as well. And I'll include a link for that in the notes for this is Well, so the commands air really straightforward. The first thing you need to do is create a directory and then navigate to that directory. Then you'll initialize get for that particular directory, and then you're gonna clone the repository that I have on Get Hub. So and that's the URL. And so on the left hand side, er, the text instructions on the right hand side of the command. So you're going to create the directory. In this case, it's called projects. I change the directory to projects I initialize get, and then I clone the source repository, and it's a very fast operation to do this. And so I'm going to go ahead and do a demonstration of this. I'm going to do it on the Lennox machine, actually out on the Google Cloud platform just to show you how quick and easy this is to do . So let me go ahead and jump on there and will run through this and I'll show you how to get the code. Okay, here we are, out on the Google cloud. Platform him in the clown show, which is the free Lennox machine that comes with the account. So I use this for a lot of my development work, and I'll show this to you later on as well that you can use this for your C sharp codas. Well, anyway, so here we are. I'm gonna go ahead and run through this now, so I'm going to create a directory called Projects. And then I'm gonna change my directory two projects and noticed that in the editor up here , it shows me that I have created my new new directory called Projects. So then I'm going to go ahead and type and get in it so that that will initialize this directory to be used for source control and has gone ahead and done that. And now I'm going to issue the get clone command. So I'm gonna go ahead and copy the URL from the get hub website. So let me go ahead and do that. I'm gonna copy that so I don't have to pace that in. And now I'll go back to my cloud show and I'm gonna type in, get clone, And then I'm gonna paste in this you, Earl, and it's gonna go ahead and grab my source. Good. So it's already done. So now if I go ahead and look at the proud if I could do an ls dash l here it will show me . Have a quick typo here. It created a CS code directory. So I'm gonna change the C s code and I'll do a directory here and you'll see that there's a directory for each of the chapters in this course. And so I'll go ahead and look at it graphically so you can get an idea here. So there's a chapter for each one, starting with Chapter four, Chapter seven, Chapter eight. If I look at one of these inside of here, then is the code for that particular lesson inside there, so I'm just gonna open that up. I'll make this a little bit bigger. So this is the C Sharp program for Chapter seven. So if you get stuck it all, you can refer to this again. If you want a copy and paste, you want to open it within visual studio code. Whatever environment you're using, this is just an extra resource so that if you get stuck on something, you can look at this code. Let's go ahead and jump back into this lesson. That's really it's pretty quick and easy to get the code, and hopefully it will save you some time if you get stuck on something. So let's go ahead and jump back into this lesson and wrap things up. In summary. I've shown you how to get the source code for this class by cloning my get hub repository out there. So again, get home is free. I would highly recommend that you use it if you have any problems at all downloading the code, contact me and I'll help you out. And also if you find any problems with the code Hey, nobody's perfect. Let me know and I'll fix it as fast as I can. So that's really it for this lesson. Thank you so much, and I'll see in the next lesson. 5. Chapter 3 Hello World Windows: Hello, everyone. In this lesson, I'm going to show you how to install our development environment on a Windows machine. So we're gonna be using dot net cord again dot Net core is a very flexible environment. It can run on Windows, Mac or Lennox. But I'm gonna go ahead and show you how to do that on a Windows environment. So, really, the steps of what we're going to do is we're going to download, install dot net core, and we're going to create a new project, Hello World, which is the traditional first program in any language. And I'll show you how to make a slight change to that and compile it. And then I'll show you how to install visual studio code, which is a really nice lightweight editor from Microsoft. And then you can use that throughout the course to edit your code. And I've also attached a PdF file with detailed step by step instructions on how to do this . So to install dot net core, you're going to go out to the following link you're going to go out to dot net that Microsoft dot com slash download and you'll see the Lincoln there And then you can download dot net core, kick off the installation and then just do a simple test after it's done to make sure everything got installed. Okay, once you've done that, you're going to create a new project. So first thing is you're going to create a new directory called CS Code. You're gonna change to that directory. So I've included the DOS commands. To do that, you're going to use the M K D. I. R Command created the directory called CS Code, and then change that CS Code directory. And then you'll fire off the command for dot net core to create the shell of a new console program. And that's the command there dot net new council Dash Dash name. And in our case, we're gonna call it CH four for Chapter four. So after that, I'll show you how to make a quick change to that, and then you can install visual studio code. One thing I really like about this you could use visual studio itself the community edition for this, this course, but visual studio code is really lightweight. That's a very quick download install. It's very flexible. There's tons of plug ins for it. I really like it because it's it is such a lightweight thing. If you install visuals studio itself, the community condition install is a pretty heavyweight process. It may take you an hour. It took me over an hour on my notebook computer. I don't have the world's fastest notebook, but it's not the world's slowest either. But the visual studio code installation process is really just a few minutes, and it's very lightweight, and it's so flexible because it's a available in so many of environments. I run both Mac and Windows, and so I like using code on both of those. So I'll show you how to install that, open your prior project and then make some compilation changes in here. So for our demo, I'm gonna go ahead and jump onto my windows machine and you'll see a study died of that in this course of me, jumping onto the Windows machine and using dot net core and visual studio code. So I'm sure you had to get all that set up and get going right away. So I'm gonna go ahead and pause the video here and fire up my windows machine and I'll show you how to get everything installed and configured. Okay, The first thing I'm going to do is go ahead and go out to dot net that Microsoft dot com slash download It will ask me what I want to install, so I'm going to install dot net core 3.1 and I'm going to download the dot net core sdk for building applications. So I'll go ahead and click on this and download that. It takes just a few seconds here and I'll go ahead now that this file is downloaded and I'll go ahead and kick off the install. It's just finishing up here, so we'll let it do that. It's going to go ahead and show it in the folder here, and I'll go ahead and bring this up and and run this So double click on this the dot net STK installer. I'll go ahead and kick this off and we'll let it run through its paces here. So it first puts up the warning message here. So I'm gonna go ahead and click install and like I say, this is a pretty quick install, so I'm going to say yes. I want this app to make changes to it. And now it's just gonna download part of the run time and we'll go ahead and run through the install. So this is a pretty quick process. It's not like installing visual studio or something like that. It takes just a few minutes. We'll go ahead and let it run through this process, and then once it finishes, I'll show you how you can type in a command to verify that the install has been complete. And then I'll show you how to go ahead and create our first program. So it's just downloading that last few pieces of this and I'll go ahead and pause the video here and let it finish the download. Okay, now it's complete. I'm gonna go ahead and click close and, um uh, now it's gonna install the sdk portion of that, so I'm gonna go ahead and click install here and let it run through. The process Here is Well, so there we go. The installation is now complete, and now I'll go ahead and open a command prompt window, and we can verify that are installation has been is working properly, so I'll go ahead and do that now. Okay, Now I'm gonna go ahead and open up a command prompt window. So So, Aiken, type in cmd and it will bring up a command prompt, and I can open up a command prompt window, and I can type in now dot net cash stash version to verify that my installation is correct . And so I've done that, and now you can see that the version is 3.1 dot 300 So now I'm going to go ahead and create a directory that we can put our code in. So I'm gonna use the command and K d i r. And I'm gonna call this directory C s code for C sharp code. And now I'm gonna go ahead and change to our directory by typing and CDCs code. And they were go. And so now I'm going to go ahead and create our first consul program so you can use the command dot net new console, and then we're gonna put in a name and I'm gonna put in ch four for chapter for So we're gonna go ahead and create this. It looks like I forgot a t here. So go ahead and use the up arrow and I'll correct this dot net New consul name. CH. Four. So there we go. It's gonna go ahead and create this this stub of a program for us for hello world. So I'm gonna go ahead and change our directory two ch four and I can go ahead and run this program by typing in the command dot net. Run and we'll be using that a lot in this course to dot to run applications, and it will take just a second to compile it. And then you'll see Hello World. So let's take a look. I'm gonna type in directory here and you'll see a number of a number of files that dot net is created for us. I'm going to go ahead and load up note pad with our program dot CS file, we can take a look at the code programmed at See us. Here we go and sit down. If I looking note pad, I can see that what dot net core is generated for, So let me drag us here to the middle of the screen and you'll notice it starts off with a Using statements will be talking about that later in the course that defines some of the packages that are available for your program and then the next line down is a name space that we'll also talk about later on. But that just basically organizes your programs. The big piece here, then, is this class program. That's the definition of a class file, and we'll talk about that. C. Sharp is an object oriented programming language. We'll talk about that later on in the course about how to organize your programs with objects. The real beginning of the program is this void main, and that is the entry point into a council programme. This piece right here with the strings and the arguments that a RGs is for arguments is that you can pass in command line arguments to to a consul program. Then the line that actually executes is this console dot right line statement, and it prints out Hello, world. So what I want you to do that is make a small change to this. I'm going to put into change here to put print out my name. Hello, world. Come in. My name is Eric, so I'm gonna go ahead and save this and I'll go back into our consul program and I'll type in dot net Run once again and notice how I used the up error you can scroll through to get to previous commands. I made a small change. Now it's going to compile, and now you can see that we've We've made a small change store program. We've compiled and edited it again. Very simple, but this is what you need to get going. So look how quick he can go. This is literally just a few minutes to install dot net core and a compile your very first program and edited so you could certainly use note pad for the rest of this course. I don't recommend it. So what you want to do is install visual studio code, which is a really nice editor. And so in the next part of this video here, I'm gonna show you how to install visual studio, download, install visual studio code, and then use that to make another change to the program and how you can use code to get going. So let me pause the video here, and then we'll look at the next part of this of how to install visual studio code. Okay, now I've gone to co dot visual studio dot com com. I'm gonna go ahead and download visual studio code for Windows. So it asked me which version I want to download. And this is the nice thing, by the way, that you can get it for all three of these environments. But you go ahead and download this now and then. Once this downloads, it's pretty quick download. I'm gonna go ahead and kick this off, and here we go. And like I say, this is a very quick installation process. It's really not going to take you a ton of time. I'm on a pretty fast computer here, but it ask you to accept the license agreement, and I'm just going to accept all the defaults as's faras the location of where to store it . I do want it to create a desktop icon sewing and add that and ah, I'm just going to keep the rest of the defaults the same. So I go ahead and kick off this install and let it run, and then once it's done, I'll show you how you can open up our code with visual studio code, and it's really a nice editor. It's gonna give you and tell a sense auto complete. There's a number of plug ins you can install for it. There's a lot of really great things with it. So like I said, that was in real time. I didn't even have to speed that up. It's going to go ahead and launch code for us, and I'm gonna go ahead and open up our file that we created earlier. So okay, so I'll go ahead a navigate to our to where I created my program in which, in this case is going to be our CS code directory. Our Chapter four. And then I'll go ahead and open program dot CS. And now you'll see the difference of of using visual studio code versus note pad. Everything is gonna be color kind of coordinated. There's ah bunch of options that will help you help autocorrect different things. If you're missing certain things, it will help you with the typing. There's just a ton of features with this, and also it'll integrated terminal a swell so you can open a terminal, and then inside that terminal, you can type commands so that you can compile your program from within visual studio code. Also, when I opened this, it says that it's recommended that I install the C C sharp extensions for this. And this is one of the the things I'll do. So I go ahead and click for the recommendations and let it install these things. No, probably do the same for you. It'll help with the C sharp code. It will help you, um, um, run in debug code and a number of other features. So that's really a good thing. And I'm gonna install the other recommendation it has for me as well. We'll take just a 2nd 1st insulation, and the second installation is now done as well. So if I go into my terminal, I can actually can compile and run my program from there. And I'll show you how to do this. Once it fires up the power shell command terminal here, it'll take just a second for that fire up. And when it starts up, we'll show you how to compile it. So one of the things you can do once you've started up visual studio code is you can use the Control plus Key, and you can make Zoom and make the program a little bit bigger. So in this case here, is that a little bit bigger fondle? Stretch this out a little bit and you can see now maybe it's a little bit easier to read. And so if you want to make it smaller, you can hit control minus and it will. It will zoom it back down, so whatever you have comfortable with, there's a lot of other options in here. I'll see if I can put a lesson and will talk about the color options. A lot of people like different colors with the editors. I'll put that in here later on in the course, but those air kind of some of the basics that you can use. And now if you look at the bottom in the terminal, I'm located in my CS Code CH four directory, and I could just type in dot net run as part of the terminal down here and it will go ahead and make the changes here. So really nice environment here. I'll go ahead and make a simple change here, and one of the things you're gonna want to remember is if you make a change in this environment, you really need to save it here before you re run it. And again you can use the up and down arrow keys here is, well, type in dot net run, and it's gonna print out my first and last name. So that's really it for this lesson. That's how you get up and going pretty to to lightweight, easy and stall processes to get up and going. It will provide your great set of tools. So either way, you decided to GOP in the cloud or with Windows. Either weighs a good environment, or you could go with both. So let's go ahead and jump back to the summary and wrap this lesson up in summary. I should you have install and configure dot net core and a Windows environment. It should. You have to create your first project and make a simple change to that using note pad also then, to compile and run up. You've made those changes using the dot net run command. After that, we installed visual studio code, which is a pretty lightweight and install, and I showed you a little bit about the tool. How you can open up your project inside visual studio code and then how you can use the commands with inside visual studio code to compile and run your projects. So lots of things going on here, but two pretty lightweight tools to install shouldn't take you too long. So now it's your turn. I've included step by step instructions in the attached pdf file to this so you can configure your own environment in Windows with both dot net core in visual studio code. Well, that's really it for this lesson. Thank you so much. And I see in the next lesson. 6. Chapter 4 Hello World Google Cloud Platform: Hello, everyone In this chapter, I'm going to show you how to set up your environment in the Google Cloud platform. And again, this is an option. You can also set it up locally on your own machine, or you can use the cloud for this. So let's go ahead and jump into the details. So in order to do this, you're going to sign up for a free account on the Google Cloud platform, which is also known as G. C P. And when you sign up for that account, you get a $300 credit and it's good for a year. So once you open up this account, you'll be billed for the any services that you incur. Against that credit, However, this thing that I'm going to show you did the the console and the editor within that console. There's no charge for running that that machine is free, so you won't use up anything on your credit. So one thing is really nice about this is, since you won't be incurring any charges, you can use some of the other services on the Google Cloud platform to use your credit on. You can try out a few services and see how it works. You will need to enter in a credit card number to open. Your account, however, will not be charged. You will go against the credit, and once that credit is done, it will ask you to activate the accounts or your account will be. You won't be able to use your account until you activate it, and that's when you would incur any cost. But the function that you're going to use for this you won't be able. You won't incur any costs with this, and it's a really a good way to get familiar with the cloud. So did sign up. For your free account, you're going to go to cloud dot google dot com slash free. And then you can read about the 12 months of the $300 credit that goes against that. And there's also a number of services that are also always free, so you can read through the details of that as well. So once you've established your free account, you're gonna log into to cloud dot google dot com and go to the council in law again. And once you log in, you'll see at the top of the screen, a small arrow that I've highlighted here, and that's where you activate the cloud shell. And that's where you can do your development on the cloud shell. It's a small Lennox machine that you can use free of charge, and it has a limited amount of storage. I think it's five gigabytes in that particular cloud shell, but it's a great place to develop code. And so here's what it will look like then. So when you log in, you'll see some information about your account, and then you'll see at the bottom, then the clouds shell that's opened up and then as a part of that, and I'll show this in a demo. Here. In a minute you can click this little pencil icon, and that will launch the editor. And so once you're there, you're going to create a directory. You're going to use the make directory can to create a CS Code directory, and then you're gonna change the director and then you're going to create a new program using the dot net new command. So I'll demonstrate all this in a few minutes, but I just want to go through the steps here. And so once you've done that, then once again using this little pencil icon, you can launch the editor and the editor. Them will be available in this top area above the screen. And so I've blown this up so you'll see this kind of scenario. Here. You'll see program dot CS and you can navigate the files on your cloud shell program using this side editor, and then you can open it up during the editor. So here's a screenshot of just the editor and what it looks like. And I've dropped in just the the code that was generated by our dot net new command. It'll generate dot net core will generate a stub of a program, and we'll put it out there for you. So then all you need to do this make a small change to this. I've made a small change that said, Hello, world. My name is Eric, and I added in just a few characters here, and then I can save this, and I could re compile it and the commands than to compile it. I need to make sure I'm in my Chapter four directory and then I just type in dot net run and it will compile and execute the program. So that's really the steps that you're going to see here in our demo. I'm not gonna go ahead and sign up for the free account. That's pretty straightforward. To do that. I'm gonna go ahead and log into my account and I'll show you what it looks like in the Google Cloud Platform or G C. P to create your first program. So let's go ahead and I'll take the positives video, and then we're gonna jump out to G. C. P and take a look at how to write Hello, world within G C P. Okay, I've gone ahead and locked into my G C P account and you'll notice up here in the top right hand corner. There's a small icon here and will say, Activate cloud Shell. So I'm gonna go ahead and click on that, and it takes just a few seconds, and that will spend up the Google Cloud shell. Now one of things I like to do is to go ahead and open up this window and its own dedicated window. So on the bottom menu here, if I click on this. It's gonna open up the cloud shell in its own dedicated window. And what I like about that, then, is once I do that, I can open up the editor and it will stack the editor on top of the screen so well should demonstrate how to do that. Now you'll see the little pencil icon. If I click on this now, it'll open up the cloud editor and it stacks this editor on top of, um on top of the the command window. So now I'm going to go ahead and check to see um, if dot net is installed so I can type in dot net dash dash version and it will tell me the version of the dot net core. It's installed. So I've done that and we see 3.1 dot 300 the code, and in this course, really, you can use any version of dot net core, but that's one of the other nice things about using the Google Cloud platform. Is .net course already installed in the show? So now I'm gonna go ahead and create a directory for our code, and I've already done that since I've been working on this platform for a while, so I want you to create the CS Code directory. So in this case, since I already have one, I'm going to create one called C s code One. And obviously, since you haven't used this system of four, you won't have that problem. So I'm going to do I'm going to now change my directory to see s code one. All right, and now located in the C s code one directory. And now I'm going to create a new .net consul program called Ch four for Chapter four. And so the syntax of this command is typing in dot net new console, which is the type of programmer creating. And then the name is sage for, So go ahead and type that in Angelica. Take just a few seconds now and it'll create our program for us. So now if I can change directory to our ch four program that we've created and I can run this by typing in dot Net run and you should know have this compile and run and it will execute. And there it is. It put out Hello, world. So what happened? There is the dot net New consul puts out a stub of a program in that directory called CH four. And this is what I now like about the Google Cloud platform is And I've created that I can go up to our editor so I can go up here on our on the left hand side and you'll see the files. And again, I noted, already had a CS code directory. So I created one called C s Code One. He can really call it any directory you want. But that's the directory that I put in this course. And so now if I look at the chapter four directory, Aiken, expand and contract these. I'll see our program dot CS file. So I'm gonna go ahead and double click on this, and now we'll see the program that it generated. Well, this is the beginning of the very first program that would have called Hello World, and it starts off by having a using statement that includes all the system functions. We'll talk more about that later. It also includes a name space called ch four, which will also talk about later as well. But the name space is really a naming convention for your programs. And then the class, which is the entry point to a consul program, is called program Itself. And that includes a main function, thes string or arguments right here. You can actually pass things into the command lines, will also discuss that later. But the main thing I want you to do is to look at this console dot right line program. I'm gonna put a small change in here again if it put it in a comma. Let's see, my name is Eric. I'm just a simple change here. And then I'm gonna go ahead and save our changes. So I'm gonna go back to our consul program again. Are are command line. And I'm just gonna type in dot Net Run once again. Now, one of the nice things about this console is you can use the up and down arrows to look at previous commands that you've run so you can scroll through these. I'll just go ahead and type and dot net run once again. And now we should see the program with our new output. So there we go. Hello. Hello, world. My name is here. Super simple change, But It's really nice that you have the editor. If you want to close this file, you can click on this again if you want to make sure your save your changes before you run it. But this is a really simple way that everything's kind of built in, that you can edit code. It's free, very easy to use. And this is what I use a lot to write code with because it's very convenient. All they need is a Web browser to get to it. So that's really it. That's how you get up and going with the Google Cloud platform and how you write your very first program. Hello, World. We're gonna use this as a baseline will actually start copying this program. We're gonna have a Chapter four of Chapter five, Chapter six all the way through. We're gonna make copies of this program, and I've included instructions on how to do that within, uh, Lennox or the Google Cloud platform to do this. So let's go ahead and jump into the summary that's really in for getting started with the Google Cloud platform. It's pretty simple. I recommend doing this. Actually, you don't have to install any software, and you can get up and going right away. So let's jump back to the summary and wrap this lesson up. In summary. I showed you how to sign up for a free account on the Google Cloud Platform or G C P. Also, should you have to use some simple dot net core commands, including the command to verify what version you have installed also should be that command to create a new project. And then how to open that project and the built in editor and make a simple change in rerun that program. So that really gives you the baseline of how to use the Google Cloud platform as a development environment moving forward again. We'll clone those directories from Chapter four to Chapter 567 and so on, and you'll use a copy command to do that so you'll just be building on the baseline of what you've done already. So it's your turn. Now it's your turn to go ahead and sign up for the account. I've included the PDF file that has detailed step by step instructions in case you get run into any problems, but it'll take you through step by step, including the things I just showed you to go ahead, sign up Fury account, set up your first program and get going. So that's really it for this lesson. Thank you so much. And I'll see you in the next lesson by 7. Chapter 5 Comments in C#: Hello, everyone. In this lesson, we're gonna look at comment statements in C. Sharp comments are a way to document your code and believe notes about important pieces of code and things that you've been doing. It may not seem like it's important when you first start, but it's a way to really leave yourself some breadcrumbs. And also, if you're working with the team, it's very important so that you can communicate to other members of your team the exact intent of your code in any nuances in the code. So let's go ahead and get started and look at the syntax of comments, statements and c sharp. There are really only three kinds of comments in a C sharp program. The 1st 1 is a multi line comment, and it's exactly what it says. It's designed to span multiple lines will look at that syntax of that in just a minute. Then there's a single line comment, which is probably the most common comment statement and C sharp. And if you look at the example on the right, that's an example of a single line comment. However, you can do multiple line multiple lines of comments with single line comments by stringing one comment statement after the other. So there's two lines of comments in the example on the right and then the last one is an XML comment where you can embed some documentation in your code. So let's go ahead and look at each one of these in a little bit more detail. So the first type of comments statement we're going to look at is the multi line comment. It's really easily implemented. It starts with a slash star, and then it ends with the star Slash so you can see the beginning and end markers for the multi line comment. They're particularly useful at the beginning of a program. If you're gonna have a very detailed description, that's gonna be pretty long. You might have include the author the date it was released, maybe some release notes. So these air intended for really long pieces of documentation that you put in the code. So let's go ahead and look at the next type of comment statement. The next type of comment will look at us a single line. Comment. This is probably the most common type of common statement that you'll use while you're coding in C sharp. So you you look at the line 5.3. It has an example. Single line comment in the syntax is really simple. It just starts with a slash slash, and so you can typically put this in line with code. You'll want to invent your comment statement said that they line up with the indentation of the code wind that it's explaining, so that makes it a lot easier to read in the comments. So let's go ahead and look at the last type of comments statement you could do in C Sharp. The last type of comment statement will look at is the XML comet. The syntax for that is it starts with three slashes In this type of common is a very special comment. It's used for extracting documentation for your code, so we'll take a look at that a little bit later. In the course, when we do our complete example, we'll put some documentation in our code, and I'll show you how to extract that a little bit later on. Now let's go ahead and look a demo where I'm gonna go ahead and the last program that we wrote Let's put some simple comments in there so you can practice putting those in and you can get used to documenting your code. So let's go ahead and jump into the code and take a look at comments. Okay, Here I am, in my Windows environment. And now I'm gonna go ahead and fire up the command prompt windows so I can type in cmd in the search, and it will go ahead and bring up my command. Prompt. I've made the font a lot bigger in here, so it's a little bit easier for you to read in the video here. So the first thing I'm going to do is change to my C s code directory by typing in CDCs code. And now I'm going to change to our Chapter four directory sewing in a type in CD ch war. And if I do a directory statement, then I can see my program dot CS file. That's right here. So I'm gonna go ahead and start a visual studio code, and then we're gonna make some comment statement additions to this file. So let's go ahead and type in code program. I don't see us and it will go ahead and launch visual studio code. So this will take just a second. And once this comes up, we'll add our comments. Statements. So there we go. You can see how visual studio code has thesis in tax in the color coding. That's one of the really nice things about using Visual Studio code is that it understands the syntax of not just see sharp but many other languages as well, such as Python Java HTML files. So it's a very handy tool, tohave. So let's go ahead and start making our comments. Statement changes before we get started making our changes. I want to show you a simple feature and visual studio code that can probably help you out quite a bit. So I'm gonna make this window a little bit bigger and then to increase the size of the characters so there are a lot easier to read. I can use the control plus statement to go ahead and zoom in on the code so I'll do this a couple of times and make the code quite a bit bigger. So it's easier to read. If you want to shift it back down, you can use control minus and it will zoom back. So that's probably a pretty good size right there. Let's go ahead and leave it like this. And now we'll go ahead to make our changes with the comments. Statements. Okay, I've gone ahead and copied an example of a multi line comment into the paste buffer. So I'm gonna go ahead and simply right mouse, click and paste this in and you'll see the syntax that I described Early slash star and then ends with the Star Slash and notice how it's all highlighted in green, and it indicates that it's a comment. So down here, I'm gonna put in an example of a single line comment, so I'm gonna put in 5.3. This isn't an example of a single line comment, and that's really it. I'm gonna go ahead and save this, and that's the syntax of how to do this and notice once again that this is all coated and green. I'm not gonna put it in an XML comment. I'll save that for later on in the course, and we'll do that during our complete example, which would be the last lesson in this course, and I'll show you how to use that than to extract the documentation out of it. So that's really it. We're ready to go. We can. Since I've saved this, I can go ahead and run this and I'll show you how to do that from with inside visual studio code. Okay, now we're ready to run our program. One of the really nice things about visual studio code is that you can open up a terminal within code itself. So you don't need a separate window or a separate command prompt to go ahead and run your program. The only thing you'll have to do first has changed to the correct directory. So I'm gonna down in our terminal window. I'm going to change to R. C s code directory and now I'm going to change to our Chapter four directory. If I do a directory, I'll notice that everything is here. And the idea is, and you'll notice it has a little bit different syntax. And that's because we're in a power shell environment. Unless though, I can go ahead and run, um, our code with the comedian dot net run. And since we really haven't changed anything, we're going to see the same output that we did earlier. It's just going to validate that we haven't made any mistakes entering in our content. So there's the output and oh, I see there is, ah, a small error and at least my typing anyway. So I go ahead and I'll change this, you know, correct this. I'll go ahead and save this and one of the things you can do as well as you can use the up and down arrows for previous commands. So I just hit the up arrow. I'm going to go ahead and run this again and we'll see that my spelling error has been corrected. And that's the life cycle that we're gonna use moving forward. So, learning the language, syntax, we're gonna be using visual studio code and I'll be running it in the terminal window within code. So now it's a good time for you to try this yourself. Go ahead and make the edits into your program. Get visual studio code, tweak the way you want it with zooming and so on, and you'll be ready to go for the rest of labs in this course. So that's it for this lesson. Let's go ahead and look a summary and tie this up. Okay, so let's go ahead and summarize what we've done. Comment statements are very important. Even though the syntax is very simple, it's important for the support of your projects moving forward. So you learned a couple of different ways to comment your code with single line comments and multi line comments, and you also learn a little bit more about XML. So that's really it for this lesson. Thank you so much, and I'll see in the next lesson, but by 8. Chapter 6 Input Statements: Hello, everyone in this list, and we're going to talk about input statements in C sharp. So let's go ahead and jump in. Input statements allow you to read input from the user or the keyboard and allows you to put in some information into your program. And they're very common within consul program. So let's go ahead and take a look at the details. The basic syntax is the consul dot reid line statement, and you'll see an example over on the right hand side in line 6.3. Underneath that comment, you'll see that consul dot reid line is being fed into a variable called My Name. And that's a string variable that we've declared earlier in the program. And we'll talk a little bit more about that in the next couple of slides. So the first thing you're going to do is you're going to start with the program that we wrote in the last lesson, our hello world program, and we're gonna add a few modifications to that, and we're gonna do that throughout the course. We're gonna continually add to our sample program to ADM or and more features, so you get more and more familiar with all the different constructs of the C sharp language . So let's go ahead and look at the code that we're gonna add in. The first thing we're going to do is declare a variable, and that's in line 6.1 and that's a string variable. We're gonna talk a lot more about data types later on in the course Next, we're gonna prompt the user in line 6.2 to enter in their name. Finally, in line 6.3, we're going to read that input into a variable called my name and then in line 6.4. We're gonna echo that back out to the user by Can Katyn ating my name to the end of the fixed string that's represented in the double quotes. So it's a lot easier to show that in a demo. So let's go ahead and jump back individual studio code. What we're gonna make those edits will add the variable to hold the input at in the input statement and in print. The result out. So we'll go ahead and compile and test that. So let's go ahead and jump into visual studio code and take a look okay now have shifted over to my Windows machine, and I already have a command prompt Open. So let's make sure we're in the right directory here. And I see that I'm in my Chapter four directory. So now I'm going to go ahead and issue the command toe load up our program dot CS file in visual studio code. So we'll go ahead and wait for that to open. And it should be the code that we've done in our last lesson and will use this is a baseline. Then add the new code. So I'm gonna go ahead and delete this line of code, and then I'm gonna go ahead and drop in some code that I have already prepared off line here. So that way, you don't have to see me type all of this in. So go ahead and and delete this and then I'll add in our new code. So here we go. I'm gonna go ahead now and paste in our new coat and we'll take a look. So, in the first line, six point when we have our string, we have our now our prompt to enter in your name and then the read line statement that's gonna put it into my name. And then finally, we're gonna print out Hello, world. My name is and then this concoct nation operation happens here a the end. So I'm also gonna delete this comment as in and replace it with our last lesson on comments . So this is Chapter six. So just a simple comment, and we'll add some new comments as we go along, so we'll go ahead and save this. Now look at the terminal, the new terminal window. And again, I'll have to make sure I'm in the right directory. So I'm going to change two or CS Code directory and then to Chapter four and then dot net run. It should prompt me for my name, so we'll let it go ahead and compile. It takes just a second here, and once it compiles it a little print out the prompt I'll enter in my name and hit the return key. So here we get printed, Eric, and there we go. That's our execution. Pretty simple piece of code that it's going to start the exercise of modifying what we've done in the previous Lessing and adding Mork owed to it. So that's all there is to it. It's your turn to try this. Now there's instructions, detailed instructions that are attached to this lesson that show you how step by step of how to do this. Practice that, and then I'll see you in the next lesson. So let's go ahead and take a quick look at a summary of what we've done here and summer. You've learned how to do basic interaction with the user and read input from the keyboard. Be the console, That red line statement you learned also a little bit about variables, and we declared a string variable to store that information. And you also learned a little bit about concatenation operations with strings to be able to print that out. That's really it for this lesson. Go ahead and make those code changes. Test it out and then I'll see you in the next lesson. Thanks a lot 9. Chapter 7 Methods: Hello, everyone In this chapter, we're gonna look at methods and see sharp. So let's go ahead and jump in will look at the syntax and how you can put a method inside our sample program. So what are methods? Methods are away toe. Organize your code. If you have a large program, you don't want hundreds or thousands of lines, all concentrated in one piece. You want to break the program up in the modular pieces that are easy to understand and easy to maintain, so a method is a way to do that. You can break up your code into smaller pieces that are easier to manage. So what's the syntax of a method? We're gonna go ahead and look at that? And then, finally, we're going to move a portion of our sample program into a method to demonstrate the concept and how it works. So let's go ahead and look at the syntax first, so the syntax. If you look at the bottom of the slide, there's an access. Specify air, a return type, a method name and then the list of parameters that you're passing into the method. And then there's the method body, so Let's go through these one at a time. The first is the access. Specify roar modifier. So this is how a method is visible. There's a number of different attributes here for public, private and protected, and we're going to talk a lot more about that when we talk about object oriented programming. So the other aspect of this is the return type. The return type. A method can return a value back to the mainline piece of code. And so this return type can be a different data type. For example, a string or a date or a in injure or a floating point value. And again, we're gonna talk a lot more about different types of data types and see sharp a little bit later on in the course. But just know that a method can return a particular value. So for in our case, we're going to return a string back to our mainline program. The message method also has a name, and so you want to name that something that's that mimics the functionality of what your method does so something like get date or get input, name or get beginning and end date or get report parameters. Those are the types of things that you want to do to have descriptive names for your methods. And then you can pass in a number of parameters to a method. So if it's doing a series of calculations, you might pass a number of data values that the method can use to do its calculation. And then finally, the method body contains the code that the method needs to do its work. So we're going to do something a little bit different starting now moving for. We're gonna make a copy of our last lab and move it into a new chapter so we can work on that. Since we're adding a lot more code now, it's going to be a little bit more manageable to make copies of what we did prior. So that way, if you make a mistake, you still have your previous code to go from. If you really screw it up, you can start over by using this copy command. I put both the syntax for Lennox. If anybody is using the Google Cloud platform that I showed earlier in the course you use ah CP Command. If you're using windows, you can use the X Copy Command to do that. And we'll look at that when we do the demonstration of our code. So what we're going to do is we're gonna pull some code out of our mainline program, and we're gonna have a method called get names. So the basic piece of the code that prompts the user for the name and and then actually reads that into the variable we're going to return that. So we're gonna have a a string based method called get name and get name is going to return the string of that name toe our mainline program. And then we're gonna put in some code in the mainline method to invoke that new method call . So once again, we're gonna build our program. The program will not function any differently than it did before. It's still gonna prompt her name and still going to print it out. But structurally, the program's going to be a little bit different, and it's gonna have a method. And so, as we ADM or Concepts now into our sample program, we're gonna add a method for each chapter for the next few chapters. And until we build up really? A comprehensive demo program that illustrates all the basic functionality of the sea short programming language. So let's go ahead once again, will jump into visual studio code. I'll show you how to copy the program. We're gonna create our method, and then we're gonna insert the cult of Method the mainline program, and then make sure that we didn't make any mistakes, will compile and run the program and tested again. So let's go ahead and jump out to our Windows machine and have a look. Okay, now we're back on the windows machine, so let's go ahead and get set up for this lab. So first, I'm going to do a directory here seat. Make sure what directory I'm in. And so I'm going to change to R. C s code directory first. And now I'm gonna make a copy of our directory, So I'm gonna make a copy of ch four, and I'm gonna put it in ch seven. So this asked me if I want to do the file or the directory. So I did that. And so now I'm gonna change my directory to to our new directory, C h seven. You do a directory just to make sure everything seems to be in place. And it is. And so now I'm going to go ahead and start up visual studio code, and I'm gonna edit program dot CS. So we'll go ahead and let this start up, and we should have the exact copy of what we had in our previous lesson, and we do. And so now I'm going to start laying the groundwork for putting in our method. So the important thing here is you want to put the method right after this mainline method , and you can tell the beginning in the end of the mainline method with the curly braces and notice how visual studio helps you with the indentation. So this is one of the great things about using visual studio code. It will help you with that indentation and help you with the method itself. So now I'm gonna go ahead and put in what's called the stub of the method. I'm just gonna put in the method itself with no code in it to get started. So let's go ahead and do that. So I'm going to talk, put in, um, and noticed that visual studio code wants to help me with what's called Intel a sense. So I'm going to put in the method dame here, Public string and our method name is going to be called Get name and I'll go ahead and put in our curly braces and notice how visual studio helps me out and puts in a matching end Beginning and end. Curly brace in here. So now for the method body, I'm just gonna take everything that was in this method here and then paste it inside here while I've already loaded up my pace Buffer with the code for that. And I'm gonna go ahead and paste that end so you'll notice that this one line is a little bit out of place here. So go ahead and add some spaces and I'll put it back in place. And so we have the beginning and end method said to be the beginning of the Methodist. This curly brace underneath get name and now the matching embrace. And so here's our core method where I'm going to return string. The string is to first declared, we're gonna prompt the user for the name, and then we're gonna go ahead and return that out to the console. So now let's go ahead and clean up our mainline code and I'll show you how to go ahead and put in the matching call now to our brand new method. So the first thing I'm going to do is remove some code that we no longer need for from our main method, since our nothing is going to go ahead and prompt and read in the name we No, no, no longer need that. So I'm gonna make a few changes here, and then I'm going to change our comments here. So this will illustrate now that it's going with our lab and Chapter seven also make a change up here is well, t just change our comment from the carry over and just note that now this is Chapter seven , so we're pretty much all set, but we have to add one important piece of code here, and I can do this when the string is declared. I can say that the string is equal to whatever is returned from our function or a method. Get name and notice how the intelligence color codes that So now our string that has declared for my name is going to be initialized right away with this cult to get named Get name is going to execute the sequence passed back the string to the main method and then go ahead and print that out. So this is an important concept. You'll use this over and over again, and we're going to use this concept a lot in our demo programas. We're gonna add a lot of methods that illustrate different features of the C sharp programming language as we go along. So hopefully if I haven't made any any mistakes here, I'm gonna go ahead and save this and then I'm gonna go ahead and fire up our terminal window and go ahead and run this so I go ahead and change to the correct directory two C s code and to our chapter seven. And the idea here is that if we haven't made any mistakes and editing this, the functionality is going to be exactly the same. But the code is going to be a lot different. So it does look like there's an air here, so let's go ahead and see what it is. Um oh, in the method declaration So it's telling us that it's a non static field. And so, if did forget something here. So to make this right, we have to have the full declaration to make this a static method for this in order for that toe work. So I'm gonna go ahead and save this again. Go ahead and run this one more time. And with any luck here we fixed our error and now it will prompt me for my name. I'll enter in my name, and it should just print it back out here. So I've entered an Eric and now we see the result. So what we've accomplished here, we've established a method. We've made our code a little bit more modular. This is a pretty simple example, but we're gonna add more and more methods to the code over time, with each chapter and at the end, our demo program be pretty big. It'll illustrate a lot of the functionality basic functionality in syntax of the C sharp language. So let's go ahead to the summary and wrap this up in summary. We've created our first method and we looked at how you can call that were execute that from the main method, you're exposed to a little bit of version ing. So we're going to start making copies of our programs here so that if you make a mistake, as I often do writing code, um, that you have a baseline to go back to for the previous lesson. So we'll have a different set of directories now moving forward for each of the lessons. And we also looked at how you can return values from a method and how their past from the method back to the main line code. So that's really it for this lesson. Thank you so much. I'll see you next lesson. 10. Chapter 8 If Statements: Hello, everyone In this lesson, we're gonna look at if statements and see sharp. This is a way to introduce conditional logic and branching into your programs. So let's go ahead and take a look. So what is an if statement? It's a simple logic or a true false statement. It evaluates a condition. So if you look at the flow chart on the right hand side, if a condition is true, it will execute one piece of code. If this condition is not true or it's false, then it'll drop through and execute a different piece of code. It's really one of the most basic logic statements in computer programming languages, so let's look at the syntax of an if statement at the bottom of the screen. You'll see the if condition, and there's a condition to evaluate, separated by curly braces that will execute that code if the condition is true. Otherwise, the else portion. There's another section of code separated by a beginning and an end curly brace that will execute the condition if it's false. So we're gonna do our typical code updates. We're going to make a copy of our program once again, and then we're going to put in an if statement in our code on our sample program to illustrate how you use it. So what we're going to do as we're going to check the length of the string that is entered when you enter in your name. So we're gonna check to make sure that the length is not zero. And if it is, if it is zero, then we're gonna say you did not enter your name and noticed the condition has to equal statements That is the test for equality and see sharp. You contest for something equal to a value greater than a value less than the value also greater than or equal to or less than or equal to. So if the name is, if they didn't enter a name meaning the string length zero, then it's gonna say you didn't enter your name. Otherwise, it thanks you for entering your name. It's a very simple piece of code. Will be adding mawr if statements to our sample program throughout. But this will get you started with the syntax of this. So we're gonna go ahead and run our program again, and then we'll test it out by entering first no name and then we'll enter in our name just to make sure the functionality of the if statement is working properly. So let's go ahead and jump individual studio code. We're gonna copy the program. We're gonna create our if statement to check the input and then we'll compile and test the program to make sure that both conditions air firing in the correct manner. So let's go ahead and jump into visual studio code and take a look. Okay, I've gone ahead and opened up a command prompt window, and now I'm going to make a copy of our Chapter seven directory and move it down to Chapter Aid. So thing in a copy ch 72 ch. Eight and it's gonna ask me once again if it's a file or directory and to give us it and say directory and go on. Now go ahead and change to our CH eight directory with the CD Command, and now I'll go ahead and open up our program that CS file. So we're going to modify the main method of this program to put in our logic our if statement So right here after the get name statement. I'm going to replace this with a piece of code that's now going to check the length of this . I'm gonna go ahead and delete this line. And now I'm gonna go paste in some code that I'm gonna give Get from our document. Okay, Now I'm gonna go ahead and paste my code that I've had in another source and noticed now that when I put this code in the indentation is not quite right, so I can show you one way to fix this. I can highlight this code in visual studio code. I can use control, and it's the close square bracket. And then I can indent the code all at once. So a really nice feature here, I can clean this up to keep Thean denting so that the code is just a little bit easier to read. So this is one tip I have for you to try toe pay attention to where the opening and closed brackets match up so that you know that everything matches up. So once again in the main method, the beginning curly brace and the end curly brace. And now, on our if statement, I have a set of matching pairs of curly braces under the if condition, and then also under the else conditions. So that's something you'll want to watch for. When you do this, I'm gonna go ahead and save my file and notice. Now that again we have the check for the length and noticed the double equal signs and then the logic of whether or not you did enter a name or not, and it prints something out. So let's go ahead and give this a try ing and open up our terminal window and I'll change toward directory. And let's give this a run and see what happens. Hopefully pasted the code in right. We don't have any air, so let's give it a shot. Terminals, Now open. So I'm gonna change to R. C s code directory and now changed to Chapter eight and put in our .net run command so dot net run. It's going to bring up the prompt, and this time I won't enter a name. I'll just hit the return key and we'll see that it catches that that logic and says that I didn't enter in a name. So is taking just a second to compile here. I have a little bit of a slow machine for my development machine here, but here we go. So I press the enter and it says it didn't you did not enter your name. So let's go ahead and run that again in this next time. Let's go ahead and exercise the other part of the branch to make sure that that works. So it's compiling. Once again, I'm gonna put in my name, and it does thank me for ruining the name. So both conditions of the if statement are firing off properly. So that's really it. We've just added a simple if statement. This is a pretty simple exercise, but again, we're gonna keep adding more and more code to the sample code as we introduce more statements in the C sharp language. So let's go jump back to our summary and wrap this lesson up, okay? And summer we've created our first conditional statement. We looked at the syntax of the if statement and C sharp and we dropped a simple example into our sample program. So you also used that condition to check the user input to see that the user did indeed enter in a name. And so this is the beginning, where you can start validating user input into a program which is very important. If you wanna have a quality program is to always check the user input to make sure it's in the right format and the data is correct. So that's really it for this lesson. Now it's your turn. Go ahead and put this into your own sample program. I've attached a Pdf instructions on how to do this with this lesson so you can go ahead and do this on your own. And remember that practicing this code is really how you learn the language by writing code . It's like a musical instrument. You have to continue to write the code. So even though these air simple examples take the time to write the code and get used to the environment and you'll really learn the language and a lot quicker, that's it for this lesson. Thank you so much. I'll see you again in the next lesson. 11. Chapter 9 Loops: Hello, everyone. In this lesson, we're gonna look at loops and see sharp. We're gonna look at the syntax and a couple of examples and some of the variations you can have. So let's go ahead and jump in and take a look at loops. So what are loops? Loops? Tell a computer program to do a repetitive task so this can be in a number of different forms. For example, it could be a set number of times, for example, maybe one to process grades for each student in the class and say they're 30 students in the class. You'll started student number one and then process until you get to student number 30. That's one type of loop. The other thing is, you might want a process. Until the condition is true. You might want across something. Process something until it hits an Indo file condition, for example, or something that indicates that the process has been completed. You can even have loops that are embedded with inside loop, so you can really have complex logic within with the combination of a number of loop. So let's go ahead and look at some specific examples and how they're implemented within C sharp. So there are really three types of loops and see sharp. The first is a four loop, and it's designed to perform a task, a specific number of times. An example I gave earlier of counting from 1 to 30. The four loop has designed exactly for that condition. The wild loop is designed to perform a task. While a condition is true, it'll keep processing, and when that condition is set to true, you can also set it up to exit when a condition is false. But when that change of condition happens, then you can exit the loop. One difference with wild loop as composed as opposed to the do loop, which is the second. The third syntax that we're gonna talk about here is the condition check is at the top of the loop. A do loop is exactly the opposite, where the check is at the bottom of the loop. After the code inside the loop is executed, the check is done at the bottom. This is just merely a convenience and syntax. Sometimes with certain types of logic, it's better perform tested. The top of the code top of the loop or conversely, you might want to do it occasionally at the bottom of loop. It's just a matter of having some flexibility there, So let's go ahead and look at some examples. So the first example is a four loop and said the four loop will set up in this case, it's gonna loop. It's going to set a variable an imager. I equal toe one. That's the initialization part of the loop. Next is the the condition for the end of the loop, and it's going to check to see if I is less than or equal to 10. In our previous example, we saw the equal equal for the a quality statement, and now this is the no less than or equal to syntax. And now I plus Plus is an increment. Operator is gonna take the value of I and add one to it. So it's simply a shorthand for saying I is equal to I plus one. So it's the anchorman operator, I Plus Plus. Similarly, there's a deck Ament operator of I minus minus, which Decker mints it. So then, in this example, it's simply gonna print out I so it's gonna print out the number each time as the loop illiterates through the next syntax will look at is the wild loop and so that again the condition is at the top of the loop and you can put some kind of condition in here to check for true or false. And then something inside your code will have to trigger that condition to not be true anymore, and then the loop will exit. Similarly, the do loop is the exact same syntax with the condition being set at the bottom of the loop . So, um and it says don't forget the trailing semicolon here. So that's that part of the syntax. Let's go ahead and look at what we're going to do here. So we're gonna once again make it a copy of our code from chapter to chapter nine. We'll use the ex cop in, Came In. If you're using Lennox or G. C. P, you would use the CPI command and this syntax for the change directory command there. So the code that we're gonna put in, we're going to declare a new variable. So its statement 9.1, we're going to declare a boolean variable. A boolean is a true false variable. And we're going to set that condition to false Now on 9.2. Underneath this comment, we're gonna put in some code to check to see that this loop is gonna execute until something is false. So we still have our call to our get name method, and we're gonna print out the name. Now we're gonna add in a check for the exit condition. So if you type in a special name, exit and all capital letters, it's going to now tell you, thank you and goodbye and it's gonna set done are boolean variable to true and will exit this loop. Otherwise, if you don't do that, it's going to thank you for entering in your name, and it will continue to ask you for your name and tell you type and exit. So this is the beginning. We're gonna build a menu down the road in our sample program here, where we can really add in a lot more features to illustrate more features of the C sharp language. We're going to continue to build on this program and make it a little bit bigger in each lesson until you have a pretty comprehensive demo program that really executes most of the syntax of the C sharp language. So once again, we're gonna use it with our dot net run command after we make our changes, and then we'll test it out, will enter in the name Well, Ah, do it one more time, and then we'll type in exit to make sure it's functioning properly. And if it is, the program will go ahead and exit. So once again, we're going to copy the program. We're gonna create our new code, will compile, run and test it and make sure everything's working properly. So let's go ahead and jump individual studio code and take a crack and putting in our conditional logic here. Okay, I've gone ahead and opened up a command prompt window and have changed to the C s code directory. So now let's go ahead to make a copy of our chapter eight program, and we're gonna put it under a chapter nine program. So once again, I'll select directory should be good to go. Well, changed her Chapter nine directory. So now I'm gonna go ahead and and launch visual studio code with our program dot CS file So now we're gonna make some modifications to our main method. What we're going to do is we're gonna put in our loop and then will also check then for the code that if the name exit is entered, then we'll exit the program. So I'm gonna go ahead and put some new code in our main method here, and I'm just going to replace the entire piece of code in the main method. So I'm gonna go ahead and paste in something new and we'll take a look at the code and make sure that it runs OK. Once I pasted in formatted and will compile it. Okay, have gone ahead and pasted in the code and also fixed up the comment appear at the top of the program to indicate this is our chapter nine code. So I've gone to full screen and made the printing just a little bit bigger so you can see the entire main method in one screen. So at the top, at 9.1, we've declared our Boolean variable to false and then a 9.2 is the beginning of our wild Lou and notice the in denting with visual studio code and the lines within here again. This is critical for you to get used to inventing the code to make sure that the curly braces line up properly and that you have them in the beginning, matching beginning and end. It's a very common mistake when you first start programming to kind of mess that up to leave out of ending bracket, and it can cause the compiler to throw some errors. So again, this is how it should look. You should have the the clear beginning with the curly brace and the end curly brace, and at 9.4 you'll see the end of the loop. So then, in 9.3, we have our check for the exit and noticed that it's gonna be case sensitive. You'll have to type in exit in all capital letters and order for that condition to match. So then, if it is exit, it's gonna think and set the done to True, it will exit the loop in the program will exit. Otherwise it will continue to prompt and ask for your name. So I'm gonna go ahead and save this, and let's open up a terminal Renda window and give it a run and hopefully if I entered everything properly, I'm gonna first change to R. C s code directory. And now I'll change to Chapter nine and then I'll go ahead and run the program and I'll test it by first entering in my name. And then I'll type in exit and make sure everything is working properly. So it's compiling now. Will take just a second. I'm gonna enter in my name. It prints out my name and now I'm gonna type in exit and all capital letters. It thanks me and says goodbye. So now we've added in the check for the exit condition and it seems to be working fine. So let's go ahead and wrap this lesson up. We'll do the summary, and this is again providing the groundwork for us adding a menu to our sample program. We're gonna be able to test out even more functions of C sharp as we continue to add to our sample program. In summary. In this lesson, we've looked at loops and see sharp. We've looked at a couple of different types of loops and the syntax of that and then as an exercise, we went ahead and created our own loop and put it in our sample program to give us just the beginning of a little bit of control of our sample programs so that we can check for an exit condition and then exit the program. So go ahead and give this a try. Have attached again the detailed step by step instructions on how to do this lab. Go ahead and try and practise it if you have problems. There's also code that you can that you can use to copy and paste some things and to help you fix some typos. So that's really it for this lesson. Thank you so much and I'll see you in the next lesson. 12. Coding Exercise 1: Okay, now that we've gotten a little bit of coding underneath our belt, let's go ahead and look at some exercises where you can practice what we've learned in addition to the exercises that we've already looked at. So there'll be a number of elements here, a number of exercises you can go through. There's four of these and will concentrate on the material that we've looked at so far from chapters 1 to 9. So let's go ahead and take a look at each one of these exercises. The 1st 1 is we're gonna right a C sharp program to swap two numbers. So the input for this is you're gonna have the first number, which is five, and the second number, which is six, which is assigned to a second variable. So you will have two variables, and then you'll need to establish 1/3 variable to do the swap. So I'll leave it up to your imagination to go ahead and do that a pretty simple program, but again, just designed to give you some more hands on experience. Exercise 1.2 is just a series of mathematical calculations, and you can look on the left hand side as faras the input of what those calculations are, and then print out what the expected output for each one of those calculations is. So there's four calculations there in exercise 1.3 we're gonna right a C sharp program that will print out the numbers from 20 to 1 in reverse order. So remember our work with loops. This is a perfect opportunity to employ a loop and then go ahead and print those numbers out in reverse order. And then an exercise 1.4 will ride a C sharp program that reads in 10 numbers from the user and calculates there some average and prints out thes values. So the input is the numbers from 1 to 10 and then the output is you're going to go ahead and put the sum of those numbers and then the average, which is the total divided by the number of values that you input. So they're pretty simple exercises with the idea. Here is the more hands on practice. So you get used to now, not just knowing the C sharp language would be able to solve some simple problems with C Sharp and again learned by repetition so the solutions are contained in attach. Pdf file To this lesson, I've also included the problem statements as well. For the pdf in additional pdf file, and I go it. Go ahead and try to give work these on your own first, before you peak that the solutions go ahead and give him our crack. You really will learn by writing mawr code. And the more you write that the faster you get at in, the more confident you get with the language. So if you have any questions, go ahead and contact me and let me know if you're having any problems. And that's really it for this lesson. Thanks again, and I'll see you in the next lesson. 13. Chapter 10 Data Types: Hello, everyone and this. Listen, we're gonna look at data types and see Sharp will add a new data type to our program, and then we'll explore other data types that are supported by the language. So let's go ahead and take a look Data types can define the information of variable can hold in a variable. We've already seen a couple of simple variables in our program. We've seen a boolean variable and a string variable. But see Sharp has a number of different variable types that that are supported. If you look on the right hand side, they're divided into three main groups. There's character data types, there's numeric data types, and then there's bully and data types. So let's go ahead and look at the details of how you declare data types and variables and C sharp. The basic syntax is very simple. If you look at the very bottom, I'm declaring an integer variable called I Selection, and this in Taxes just end and I selection. I can also initialize that variable when I declare it so when I declare I selection in this particular example, you'll notice I'm setting it to zero right away. One of the things that may be hard to get used to, and C sharp if you programmed and some other languages is variable. Names are case sensitive. So in this next second bullet it the illustration is here that I selection and all lower case and I selection and all uppercase and I selection, starting with just a capital letter. I are all three different variables, so that's something you'll have to pay attention to. We already talked about the initialization of variables in The last note on Declarations is Don't forget the semi colon most lines and see sharpened with a semi colon, and it's required. So here, the different data types that are supported in C Sharp. It starts with bullying that we've already seen. And then there's a couple of character variables that air next, a bite and a character that Characters is a single character that is a 16 bit character and a bite is a smaller character that is an eight bit unsigned manager, so you can see the values that are supported, and I won't go through all of these. But some of the more common types are decimal and float for floating point or real numbers , so that's a number with a decimal point. Another common type is an imager, which is a 32 bit an injure, and you can see the range of values that you have. If you need a little bit more space, you can have a 64 bit signed integer, which is a long A short, then, is a shorter version of that, which is a 16 bit manager. And then there's an unsigned imager as well some of the other types that are illustrated here at the bottom or an unsigned long in an unsigned short. So those air probably not quite as common as some of the other variables on here. So what are we going to do in this illustration? We're gonna make a copy of our program once again. So you're getting used to that. We're doing that, and each lesson now, and there's the commands of how to do it on both Lennox and Windows, and then we're gonna add a simple variable to the top of our main method. We're gonna add this variable right here, this imager of ice election. Next, we're going to start installing and menu, and we're gonna add to this menu as we ADM or examples in future chapters in this class. And so first, we're gonna have a Siris of right sections, right line code fragments that are gonna put together the beginning of our menu will have a selection one in a selection. Nine. If you choose Selection one, it's gonna call our get name method that we've already created, and it'll prompt you to enter your name and then it will echo it back out. So that's that. This particular section of code is for selection one. Then we're gonna have a selection for exiting instead of typing in the word exit. Now we're going to select it from the menu, and that will be this selection right here. And this is all put within our wild loop that we installed earlier in one of the earlier lessons. So let's go ahead and then look at how we're going to run this thing. So after we put it in will run, the program will test our menu selections will test both menu selections. First will test the selection and to enter your name and you can see what that's gonna look like. And then we'll test the exit selection so still pretty simple. But now we're starting to build a framework that we can add even Mawr toe our demo code as we go along. So for our demonstration, we're going to jump into visual studio code will copy the program, will add our new variable and in the menu, and then we'll compile and test and run the program. So let's go ahead now and jump into visual studio code and look at the demonstration of how we do this. Okay, I've gone ahead and opened up a command prompt. And let's start by copying our Chapter nine program to our chapter 10 program. And there we have it. We see a familiar prompt here and there we go. So I'm gonna change my directory to Chapter 10 and then I'm gonna go ahead and open up visual studio code with our program that CS file. It takes just a second for code to launch. And so I'll first start with putting a variable in the very upper part portion of our main method, which is our new integer variable for our menu. So go ahead and put that in first and code is just finishing, loading up. Some can replace this section of the code right here because I've put a new comment and as well, so I'm gonna go ahead and paste the sense so you don't have to watch me type it in. And, um here we go and I'll go ahead and clean this up a little bit. So there we have it. I just put in a new comments. It'll little reference the documentation. And then here's our new editor variable of ice election. So next I'm going to go ahead and put in this new loop code with our menu code and the too if blocks that will process the selection of those. Okay, Now I'm going to go ahead and remove our loop, and I'm gonna replace it with some new code. So here we go. I'm gonna go ahead and remove this portion, and now I'm gonna go ahead and paste in a new piece of code that has the rest of our code in it. So now you'll see that we have are our menu in here are prompt for entering in the menu selection, and you noticed there's a new piece of code in here that I'm going to convert the string that's returned from read line. I'm gonna convert that into an imager. So in C sharp, you need to explicitly convert variables from one type to the other. Otherwise, if you don't do that, it's going to throw compiler air. Next, we're going to go ahead and check the selection. And here's our first if block that says, if the selection is equal toe one and remember, you need to equal signs for the equality check and see sharp, and then it's gonna go ahead and execute, get name and print out the results. And if the selection is equal to nine, then it's gonna go ahead and say thank you and goodbye and notice how everything lines up properly within these loops. I'm gonna go ahead and fix up this indentation piece right here and we've got a couple of blank lines. I'll go ahead and remove those. I'm gonna go ahead and save the program here. And with any luck, if I've done this correctly now we can add Run this and make sure that our program works properly. So let's go ahead and do that. Okay, Now, I've gone ahead and opened up the terminal window and let's go ahead and run our program and check to make sure everything's working properly. So now it's compiling. It will take just a second, and now it's gonna ask me for the menu selection. So I'm gonna enter in selection number one, and I'm going to enter in my name and it prints it back out. And now I'm gonna in Aaron, our exit selection Number nine. And the program is exit successfully. So we've integrated our new menu system, and we're gonna continue to build on that in the next lessons. That's really it. For this lesson. Let's jump back to the summary and wrap up this lesson in summary. We've looked at different data types and supported by C. Sharp. We've looked at several examples and we added a new data type to our sample program, although it was a pretty simple example. We added a menu structure to be able to process our new selection, and we're adding the framework to add more functionality for the rest of lessons in this course. So that's really it for this lesson, it remember the Attach pdf file gives you step by step instructions on how to do this. So the assignment is to go ahead and drop in this new code for Chapter 10 before you move onto the next lesson. That's it for this lesson. Thanks so much. I'll see in the next lesson by 14. Chapter 11 Exceptions: Hello, everyone in Chapter 11 we're gonna talk about exceptions in C sharp. So let's go ahead and take a look and see what exceptions are and how to code them. So when you get an air, that program is run some type of fault or an error condition. An exception is designed to handle something gracefully so it can avoid crashes in any kind of mystery messages. So anytime there's any kind of error condition, instead of just letting the program crash exceptions, Air designed to handle those exceptions gracefully put out a perhaps, ah, a much more understandable error message and then take the program to a known state. So let's look at the syntax of how you code an exception and see sharp. It's basically a try catch block. And so in the first part of the code, if you look on the right hand side of the screen, you'll see the first part of that is a try block that's surrounded with the beginning and end curly brace. It's very common in C sharp, so that is the code where you want to isolate. If an error happens, then the catch block has some code to process that error condition. So if any type of error happens inside of this tribe, block the catch block, then will get the execution transferred to it. And then you can print out a message and return the program to a known state, so it could be a lot more complex than this. But we're going to start with a very simple air condition, and then I'll show you how the code so that you can avoid those types of errors. So the air that we're going to show here is in our new menu that we coated in the last chapter. If instead of entering in a one or a nine, that's a valid selection. What happens if you enter in and a when you get this error message right here that says, it's an unhand aled system format exception, and this air happens when you try to convert that string into an energy. Remember the the piece of code that we had in the last chapter to convert the string into a manager? Well, it turns out, if you put an invalid imager type in there and try to convert it, it'll throw an error, and it actually jumps out of the program. So what we can do is put in a try, catch block around that conversion like this and that will handle this air. So in the first part of the code and 11.1, we're gonna put in the tri portion of this that we're gonna surround that conversion to imager in the try block. Then in 11.2 in the catch block, we're gonna put out that you've entered an invalid selection. And since this whole thing is in our larger loop, then a little just returned. Two are the top of the loop to the menu once again. So what we're gonna do is we're gonna run our new code. We're gonna after we put in our error condition and are exception, handler, And make sure that it does work when we put it in. And this is how it should work is that if I enter in an A instead now instead of that ugly air message in the program crashing, it now prints out you've entered an invalid selection. So let's go ahead and will jump back into visual studio code, will put in our error handler and then we'll compile and run the program to make sure it handles it successfully. So let's go ahead and jump individual stood studio code and take a look. Okay, Now I've gone ahead and opened up my terminal window, and now I'm gonna go ahead and ex copy the chapter 10 code that we had to chapter 11 so that we can input are exception handlers. Once again, it promises, and I'm gonna go ahead and change my directory to chapter 11 and I'm gonna go ahead and open up visual studio code to our program dot CS file. Okay, Now that visual studio's loaded up, I'm gonna go ahead and run this program, so dot net run and let's see if we can illustrate the air condition. So it's gonna compile first, and then it will display our menu. And then again, instead of putting in the one or the nine, that's the valid selection. I'm gonna go ahead and enter in a and we get our unhand Aled exception. So let's go ahead and put some code in now to handle the exception, and then we'll run and test it again. Okay, I've now entered in the code for the try catch block so that we can validate the conversion from a string to manager. So if you look at the comment here 11 point when we're gonna validate this, here's the beginning of our tribe block. The tri section surrounds. Then again, this conversion where we're reading in the ended during converting the string to an energy er And then here's our new error message we put in. It'll put a space here just to make this a little bit cleaner. So go ahead and save our program and let's run it and make sure everything's working, okay? And I'm located in the proper directory here. I'm in the C s code Chapter 11 directory. So I'm gonna go ahead and type in dot Net run down here and with any luck, here we go. Oops. Does it run and we'll go ahead and try invalid selection. First will try putting in our A now and notice it does handle it. It says you've entered in an invalid selection and I'll go ahead and enter. And nine So pretty simple piece of code. I'll note that when you put in try blocks in the future, you can look for specific errors, but that's a little bit beyond the scope of this particular lesson. So let's go ahead and jump back into the summering and wrap this up. So in summary, we've looked at exceptions and how to co to try catch block. And we put one in our sample program to handle a simple air condition in handling our menu entry selection. So that's really it for this lesson. Go ahead and put the try catch block into your nd your program now on your own machine and just a reminder that the attach pdf file has the step by step destruction instructions to help you along in the lab. That's really a for this. Listen, thank you so much and we'll see you in the next lesson. 15. Chapter 12 Switch Statements: Hello, everyone In this lesson, we're going to talk about a switch statement and see sharp. So let's go ahead and jump in and take a look at the code. What is the switch statement? It's really in a way to organize your code based on a list of choices, and it's a because of the syntax. It's a lot simpler to organize when you have a number of different selections based on a numeric selection, for example, to put them in a case statement, it's much easier to read. Switch statements are also known as a case statement. So let's go ahead and look at the syntax and will be a lot mawr evident with this syntax looks like. So if you look on the right hand side will see the syntax of it of a switch or a case statement. The switch is on a particular variable, and in this case I've declared an energy variable called Case Switch, and then the switch is based on the variable itself at the top of the statement. Then you can see that there's a number of cases or conditions then that are are based on that particular value of case which. So, in case one, you can see that there's code organized for that, followed by a break statement, and the brake statement will break you out of that case statement. This is important if you don't put the brakes statement and it will go ahead and drop down to the next case and then the next case. The last item in the case or switch statement is the default case. And that way, if nothing is met, then you can put something in to execute. If it doesn't match any of the conditions, it will execute that one. So it really does make things a lot simpler. So we're going to reorganize our main menu with a switch in case statement that will reorganize our menu selection. So let's go ahead, and the first thing we're gonna do is make a copy of our program like we've done in the last few exercises, and then we're gonna go ahead and replace R R K statement. So again, there's multiple lines for each case that's enclosed with brackets. And then there's the code that you're going to execute for each one of those cages cases, and then the catch equates to the default in this situation. So let's go ahead and look at this. Now are our new code that we're going to put in instead of our If statement, Dennis, we're gonna have a case for selection number one, which is our menu entry number one, and we'll organize our new code there. We'll have a case for nine, which is our exit statement and then under default. Then we'll have our invalid selection. So we'll go ahead and drop this code in again in our demo. We're gonna copy the program. We'll add our new case statement and then we'll run the program. The functionality should be exactly the same as before. We're just replacing it with a new, more streamlined syntax. And again, we're laying the groundwork for putting even more menu selections into our sample program. So let's go ahead and jump into visual studio code and take a look at it and see how this new code runs. Okay, I've gone ahead and opened up a console window or command prompt window, and I'm gonna go ahead and make a copy of our program, as we've done in the last few exercises. So I'm gonna copy from chapter 11 to Chapter 12. Here we go. I'm gonna go ahead and change to our new directory, and then I'm gonna open up visual studio code with our program dot CS file. There we go. Okay. So now I'm going to remove this section of code right through here. So starting it a comment with 10.4 there are, too. If blocks of code, I'm gonna go ahead and remove both of those. And then I'm gonna drop in a new piece of code that has our case statement. So let's go ahead and do that and see what that looks like. Okay, I've gone ahead and open up a terminal window. Now, let's go ahead and run our program and make sure everything works the same. So I'm gonna go ahead and run through our menu selection. So if I enter in selection one I can put in my name. And if I enter in selection nine, it exits the program. So it appears that everything's working the same as it did before. So we've just organized our code a little bit differently and illustrated how to use a switch in case statement within dot net. So let's go ahead and jump back to our summary and wrap this lesson up. In summary. We saw a basic switch statement and how to code out the different conditions for those case statements. We also learned how to organize our code to make it a little bit easier to read. So particularly when you have a large number of selections and we will. By the end of this course, we're going to be adding mawr conditions to our case statement into our menu to illustrate even more features of the C sharp language. Just remember again there's the attached PdF with step by step instructions So you go ahead and drop this piece of code now into your sample program. And remember, don't just watch the videos. You have to practice writing the code. That's the only way you're really learn to code is by practicing. Thank you so much, and I'll see you in the next lesson. 16. Chapter 13 Arrays: Hello, everyone In this lesson, we're gonna look at a raise and see sharp. So let's go ahead and jump into the material. A raise air, really just a collection of data. So if you look at the figure on the right, there looks like a spreadsheet, right? There's a column for on an index column and then a row index, and so this is a two dimensional data structure. So to address this data structure, you would address it by two dimensions. The 1st 1 would be the row, and the 2nd 1 would be the column, So a raise can be one dimension. So it might be just a column of data. Or it might be a two dimensional ray column in a row, and it could be three dimensions for dimensions. It could be a zoo. Many dimensions, really, as you care for. I found in practice, though, that once you get past three or four dimensions, the purpose of the structure really becomes very confusing. So in reality, if you have one or two or three dimensions, it's a great data structure to use its It's used for ah, perhaps cashing data or looking up data So let's go ahead and look at an example of the data structure of how we initialize it and how we declare them. So if you look at the basic array syntax, the first thing is, if you look on the right hand side of the top, we're going to see a type, and that type then is followed by some square brackets, and then you have the name of your array. So in this case it's a rain name and the next example, another only declaring an array now of imagers with the square brackets. But now I'm also initializing the data structure at the same time, and the data is delineated by the the opening and closed curly braces and then the data separated by commas. In this case, they're all imager. So I have five values of 95 90 to 88 81 in 75 in the next example. Then I'm declaring an array of strings, so same syntax. It's just a different data types, and I'm putting the days of the week in here, so they're separated again by commas and since their strings there delineated with the the double quotes. So Sunday Monday, Tuesday, Wednesday, Thursday, Friday and Saturday. So and ready can only have one type of data. So, for example, an end to string a double afloat. They're they're on lee one type per array. You can also then have an array of classes or custom classes that will talk a little bit later about in this course, and so that you could really have some nice fits with collections or raise of custom classes, and then we'll talk about that later. So for our code up, they were going to continue our same method. We're gonna make a copy of our program. If you're using Lennox, you can use the CPI dash our command windows. You're going to use the X copy command. We're also gonna be adding a new menu option into our program. So first off will add that menu. We're gonna add a print statement here, which is selection number two, which is our array demo. And then we're gonna add in a case statement underneath that that print statement that will handle our new code. So if you look at lying 13.3 or the comment for 13.3, it's a case statement that's gonna handle that. And then a call to our new method that we're gonna add. So we're gonna isolate our new code in a new method and will keep doing that moving forward so that we can expand our DeMint program and you can get more and more functionality and understanding of the language. So here's our ray demo method, and we're gonna start it off with the declaration that we had seen earlier in the slide declaring an array of strings for the days of the week. And then we're simply going to put in a loop now a four loop that we also talked about earlier. And we're gonna cycle through that collection and print out each day of the week and notice the syntax for days when we address a particular element of array, we use the square bracket and then the number or the index into that array. And so when we're cycling through this were declaring an imager of zero and going to lessen Tariq Little six that we're going from 0 to 6 and then we're cycling through each element of the array. Now, one thing about C sharp that you should know is it? Zero index based array. So the first element of the ray is days sub zero. And that's how you can talk about that is saying sub zeros of one. That's ah, one way of indicating what element of the array you're going. So you're going from element 0 to 6 and you're printing out each day of the week, So pretty simple example. But it does have some intricacies to it that you need to understand. So once again for our demo, we're going to start by copying the program. We're gonna add our new case statement. We're gonna code are Ray Demo Method and then once again, will go through our compile process and test out the code to make sure everything works. OK, so that's really it for this. Let's go ahead and jump into visual studio code and take a look at the hands on part of this and the demo of building out this next function in our sample program. Okay, I've gone ahead and opened up a command prompt window on my Windows machine, so let's go ahead and copy our Chapter 12 program to Chapter 13. We'll go ahead and do that takes just a second, and we verify that it is a directory. So now will change to our Chapter 13 directory, and then we'll load up visual studio code. So there we go. So the first thing I'll do is go ahead and drop in our menu in our new case statement and then following that will put in our new method. And then we'll give it a try and make sure that I didn't make any mistakes while we're entering in this code. So there we have it. We have our new We have our program from the previous exercise. And so right here underneath this block 10.2, I'm gonna drop in our new right line statement and then right after this, then I'll add in our new case. So add in a case to write down here for our new case for our new function that we're gonna put in. So let me go ahead and positive video while I go grab that code and I'll drop it in, and then we'll take a look at that. Okay, I've gone ahead and dropped in the new code for our demo program, and the first thing that I added was our new selection to the menu. So it's the right line statement with selection number too far, Ray Demo. So then following that, I added a new case statement here for our array demo. So if you look at this line here of 13.3, um, it's our new case statement with two and then our call to our new method, which is the ray demo. Don't forget to put in the break statement said that you can have the control out of the right part of the case statement. So then I added our new method, which is theory a demo. So first I declared our array of strings, which is our days of the week. And then I added the declaration for our imager variable, which is our loop variable. And then I just cycled through from 0 to 6 and printed out each day in the collection. So that's really it for the demo code. So let me make sure that I have saved this, and that's one tip that I've for gotten a couple of times. While I was running this to save this and wondered why my changes weren't being process to make sure you save it. It's a very simple Mr Mistake, so I'm gonna type in dot net run and make sure that our code is working now. Hopefully, if entered in everything correctly, so we'll see our should see our new menu come up and then I'll select selection number two , which is our new menu entry. I'm gonna go ahead. It's like that now, and it prints out all the days of the week, so it looks like everything's working. Okay, One of the things that I suggest is that you make sure when you're entering in this code that thes currently braces lineup and that you use thes lines within visual studio to help you. It's a very common thing to forget a beginning or unending currently, brace, and it won't compile a little costume errors, and we'll look at some tools and another chapter within visual studio code that can help you manage this. But the syntax highlighting also shows the comments and green, So if something is wrong, you'll see the color coding change, and you'll get used to that over time. That's really in for a raid demo. Let's jump back to our summary and wrap this lesson up in summary. We looked at a raise and see sharp. We looked at the syntax of how you declare them. And then, on a demo program, we created a basic one dimensional array and added that to our sample program. In addition, we made some coding changes to display the values of the ray and showed how you can use a loop to cycle through each element of the array using a four loop. So we ended this to a new function to our program and added it in along with the new menu selection in the case statement to make sure that that always wrapped up in one example so slowly were adding more and more features that demonstrate all of the constructs of the C sharp language and our demo programs getting a little bit bigger each time. So that's really it for this lesson. Thank you so much. I'll see you in the next lesson, but I 17. Coding Exercise 3: Hello, everyone. In this lesson, we're gonna look at our third group of coding exercises. So let's go ahead and take a look at these. These are gonna be based on the last chapter that we looked at, which is Chapter 18 again, these are going to be simple, straightforward exercises that kind of give you some muscle memory. So you get some practice with actually implementing these string functions. So the first exercise is 3.1, and you're gonna right a C sharp program that reads in a string and prints out the length of that string. So if you look at the table below, if the input is this is my input string, it's going to calculate the length of that string, which in this case is 23 characters and print that out. So let's go ahead and look at the next one, which is exercise 3.2 and you're gonna right a C sharp program that prints out the first and last character of the input. So if you look at the table, the input string is this is my input strings. So the expected output the first character is an upper case T and the last character is a lower case G. And then in the last exercise, 3.3, you're gonna right a C sharp program that converts all of the characters of the input to upper case. So if the input on the left hand side is this is my input string, which is a mix of upper and lower case than the output would be. This is my input string all in uppercase. Pretty simple programs should not take you long to knock these out there again. Just go ahead and give these a try the solutions air contained in the attached pdf file along with the problem of statements as well. So you can download both of these. So that's really it for this lesson. Thanks again, and I'll see in the next lesson. 18. Chapter 15 Using Statements: Hello, everyone in this chapter, we're going to talk about using statements, So let's go ahead and jump into the material. A using statement is what you've seen at the top of the code. We've had these in their code, but we haven't addressed it to this point. So what it does is it allows a particular name space or a collection of code, which is really just a code library and mixed available to your program. So if you look on the right hand side, we've seen this using system and in the system package, there's a number of functions that are defined that we can reuse. Well, it turns out there's a lot more granular and lots of connections with lots of packages that are available with the dot net framework. So there's another one here system dot collections system Doubt link, which you can use for queries and all kinds of ah advanced expressions system dot text for processing text and system dot threading for multi tasking and you'll see that in some of these, then you can and granular Aly include even just portions of a particular package. So in this case will look a system dot threading dot task. So that's just the task handling portion of the threading, so you can really think of these as a shortcut. But the main thing that you need to remember is it makes the functions within that name space. And that's what these air called name spaces. And it makes it available for your program to use thes pre built functions that make C sharp such a powerful language. So the sin taxes you define these at the top of your program. And if you look at the syntax on the right hand side, you see when saying using system dot Consul to this point, we've had just using DOT system. But if we include the console package, then we can simplify the right line statement by dropping the consul dot right line portion of it because we've already made this entire package available to our program. So it's a way to really simplify our programs by carefully considering the using statements we have at the top of our program. And then we can simplify our code by just accessing the function name without the package name in front of it. So let's look at that in a little bit more detail. So our program previously in our hello world program we had a using system up here, and then we had a consul dot right line statement. So if we modify now, we make a few modifications to this and we we have using system DOT Consul. Then we can simplify this program so that it just has the right line statement and we can drop the consul dot right line portion of that. So we're gonna go ahead and take a look at that in a demo once again will jump into visual studio code. We'll create a new program just to play around with. So we'll kind of break our paradigm here of copying from the previous lab. We'll go ahead and create a new program. We'll add the new using statement, and we'll just verify that we can simplify that code and we'll run it to just make sure that it runs again without any problems. So let's go ahead and jump into our environment with visual studio code and take a peek. Okay, here we are, back in our windows environment, and I'm gonna go ahead and create a new directory for our Chapter 15 code and I go ahead and change to that. And then once I get there, I'm gonna go ahead and create a new program, and it's going to be a council programme once again. So we'll go ahead and let that create it. And then we'll go ahead and open it up in visual studio code and take a look at the code make are simple modification. With the using statement, we'll go from there. So So let's go ahead and open up visual studio code. And once, once it loads up, we can go ahead and compile this and run it just to make sure everything's running, okay, and then we'll make a quick change to this and show you how you can simplify this just by modifying the using statement. Okay, so I've gone ahead and open up a terminal window, and I've gone ahead and changed to the correct directory. So just to make sure that everything is OK, we'll give this a quick run and make sure that everything is working fine and we see are expected. Hello, world. Now let's go ahead and make a simple change to the program, and I'll show you how you can just simplify it by changing the using statement. Okay, I've made a couple of simple changes to the program. You'll notice they've added a new using statement here for system dot console. In this case, we have to use the static directive along with it as well. And I'll talk more about that a little bit later in the course, when we talk about permissions and types of things for methods and object oriented programming, so we'll talk a little bit about that more later. But the other change I made then, as I took out the consul dot right line peace, Right, So the consul dot is now removed. So let's make sure I'm gonna go ahead and save this and go ahead and run it again again. If everything works right, there should be no change here, and we're just simply re running and simplifying the code just a little bit. So there we go. It says, Hello world. The simplification in this case is pretty trivial. It's only one line, but if you had hundreds of these calls or even thousands of these calls throughout a program, it might be a significant saving to simplify your program. And do you have carefully think out the using statements and what packages and name spaces you're including in your programs? There are also some tools out there that you can look at your code through what's called static code analysis to look at dependencies in your code and help improve that design. But that's a little bit beyond the scope of this course, and particularly this lesson, but that's it for using statements. So let's go ahead and jump back to our summary and wrap this lesson up in summary. We looked at using statements in this chapter. We saw how to invoke the using statements where to place them and how you can update your code to simplify something's depending on the syntax that you use for the using statements at the top of your code. So we looked at some examples of how you can use those to simplify and also talked about how package management and dependencies play a part of a larger design within C sharp programs. So that's really it for this lesson. Thank you so much and I'll see you in the next lesson by 19. Chapter 16 File Output: Hello, everyone. In this lesson, we're going to start talking about file operations for file output and file input. So first in Chapter 16 we're going to start with file outputs. Let's go ahead and look at some of the details. Writing and reading files is are some of the most common activities that you'll have in computer programs. So the sequence of events is you open a file first to create the file or open an existing file, and then you write the data to the file. And then finally, when you're done with all of that output, you will close that output file so that it's no longer available for processing. So let's look at some of the details of how you would actually do that. And c sharp. So we're gonna have an example. We're gonna add a new menu item. As we've been doing with our sample program, we're going to create a brand new file that we're gonna write some output data into that some example data into that file, and then we'll close it at the end of the sequence. When we're done, we contest that out by opening up the file in note pad Or if your analytics operating system, you could use Nano or the V I. Editor, open it up. Just ensure that the file is has the data that you expect in it. So once again, we're going to make a copy of our program that as we've been doing ah, along. If you're in Windows, you'll be using the X copy command. And if you're using Lennox, you'll be using the CPI desh Heart Command. So please note that you're gonna be copping from chapter 13 to chapter 16. As in the last couple of lessons, we've done some code that really was a one off example for those. So we're gonna go back to the last where we had our kind of master demo program and move forward with that, all right, so far as the code. Pretty straightforward. We have a repetition going here. We're gonna add new menu selection for our file output demo. So would be item number three. And then we'll also add in a case statement for that as well. So that will be case number three and will be handling our file demo method and then really , the meat of the demo of this is our file demo method, and I walked through these. So we're using the system dot io dot stream writer collection to do this processing. So in 16.2, we're creating a string array. So this is back to our array example, and we're creating an array of strings, and it's just a simple declaration here where we're gonna have 123 strings next in 16.3. Then we're going to declare a variable of type system dot io dot stream writer and then Teoh create that will use the new operator for the same thing system dot io That stream writer and them will give it a name and notice that we have to have a special syntax for the name using the at sign for that. So important to catch that if if you don't put that in, you'll have definitely have some problems compiling the program. And then once we've created the Stream writer, then we're going to process each string in the collection. So we're declaring a single line which is of type string, and then we're iterating with our for each through this collection of lines, so it'll be 123 lines. And then we're gonna use the file dot right line statement to write that out to the file. So it's pretty simple structure. It's really combining Cem concepts we've seen already, but it's it's a pretty efficient way toe writing files and see sharp so very, very easy to Dio. So again, just to summarize, we're gonna copy our program. We're gonna add some new menu options in a case statement. We're gonna go ahead and then code our file demo method will compile it and run it, and it will verify our output by opening it. In this case, I'll be using Windows Cell. Open it up with note pad just to make the file, make sure the file really has the data that we're expecting it. So let's go ahead and jump under our Windows system and take a look at this next exercise. Okay, so now we're on our windows machines, so I'm gonna go ahead and and copy our Chapter 13 directory and copied to our new directory for Chapter 16. And once again, I'm gonna copy that whole directory, and then I'm gonna change to our new new directory that we just put in here and then let's go ahead and, um, open up visual studio code with our program dot CS file. So when this opens, what I'm going to go ahead and do is add our new men shoot menu option as well as a case statement to handle that. And then I'll drop in the the code for our methods. So we'll do this in a couple of steps here, go ahead and let this ah, open up. And then after its opening up about the first step off, go ahead and drop in the new menu statement and then we'll go ahead and put in the case statement. Okay, So when a head and dropped in the coding changes to our program. So let's go ahead and take a look at these on line 18 right here. If I scroll on across, you can see that I've added our menu option for the file output demo and I'll scroll on down. And I just added the case now for our case number three for a menu selection to handle are filed them a method I noticed. I've missed a break statements here, so I'm going to go and put that in and go ahead and ah, save this William here thinking about it. Go ahead and say that. And now when I scroll on down at the end of our main method, this is where I put in the code for the file demo method. Again, we're creating this array of string or a strength array of strings. And then we're going through and Iterating through that first, creating the output dot txt file and then our for each loop, riding out each element of the ray. Pretty simple and straightforward. I should note that I have been dropping in these new methods right after the main method. You can really put them in any order you could put them at the end of the program. If you think that makes more sense to you, just for me, it's always easier. I just find the end of the main method and have been tacking these on and just make sure that the formatting aligns with the close of my main method. It's pretty easy to drop a new method into the wrong place, but as long as you look for the end of that main method, that's my tip for you. That's what I have been using. So let's go ahead and give this a run and make sure that it works here, so I'll put our dot net run command in. It will take just a few seconds again. My development sheen machine is not the world's fastest machine, so it takes a few seconds here to compile. But then I go ahead and select that from the from the ending statement here saw Select our file output demo and don't go ahead next to the program. And with any luck now, if I type the output file and this is ah DOS command line thing where you put in the command type in the name of the file handle to scroll that file out to the string, we can see that are elements of our array have been written to the file so pretty, pretty straightforward. Ah, that's ah, our file output method. So let's go ahead and jump back to our summary and wind this lesson up. In summary, we've begun our look at basic file operations. We started with an operation to create a file. So again, this is one of the most common things you'll run into when you start writing a lot of programs. Reading and writing files is kind of the bread and butter of computer programming. So you created a data file using information from the previous chapter. So we in Stansky ated a simple array, and we looked through the collection after we open the file, and then we close the output file at the end. So that's really it for this lesson. Thank you so much. And be sure to go ahead and put this exercise in the attach. Pdf file has the instructions on how to do this. Remember, just get a little more practice each time until you get are are large sample program and then you'll be using that to implement our project at the end of this course. So that's it for this lesson. Thank you so much, and I'll see in the next lesson 20. Chapter 17 File Input: Hello, everyone In this chapter, we're going to continue our examples of looking at file io operations or input output operations. So let's go ahead and look at some of the details again. This is another very common activity. To read input from a data file on a computer program. You can use it to initialize data. You can use it, analyze reports, all different types of scenarios of very common operation. So in this example, we're going to open up an existing file. We're going to read the input data until we had end of file. And then we're going to do a little bit of data processing with that, and we'll read data until we hit an end of file conditions. So let's go ahead and look at some of the things that were going to be doing in this exercise. So we're gonna create once again a new menu item, and then we're gonna open an existing file. In fact, we're gonna use the file that we created with our file right exercise in the previous chapter. So once we copy that directory over that file, be existing and we'll read the data that's in that file and we'll write it out to the screen. And we also do a little bit of other processing. So once again, we're gonna be adding our menu operations. So we're gonna add selection number four that's displayed in here, which is our file input. And then we're gonna add a case for for that as well. So then the main meat of the program, like in the last demo that we did, is in the file and put demo methods. So again, this is a new method that will be adding and we're initializing two variables at the top of this. If you look at the very top of this code here, we're initializing encounter. We're gonna count the number of lines that we read in, and then a string variable called Line that we're gonna use to pour our line by line processing and in 17.1. Then we're opening up a system dot io dot stream reader. In the last chapter, we use Stream writer. Now we're using Stream Reader, and we're gonna open that file that we created output that text again that will be there since we're copying the whole directory over. And now we're using our line variable, and we're calling filed out read line, and this returns null when it hits an end of file conditions. So no is a very special variable in C Sharp. It's not zero. It means that there's nothing there, so it's a kind of an empty variable. So it's a very special thing called null, and it's used extensively in computer science and also in C sharp. So then, in Line 17.3, we're gonna print out each line as we read it, and then we're gonna increment our counter. And we have a syntax here where we're implementing the counter with a plus plus. So you could say counter is equal to counter plus one to do the increment. That way, a shorthand way of doing that. And C Sharp is to use counter plus plus in a linker minute. Then it's very in and 17.4 we're closing our file, and then we're writing out the count of how many lines that were written in our file. So this is what our input will look like. So once you have the menu up, you'll select item number four. You should get that input where your echoing the contents of the file. And then it's going to say they're three lines in the file so far. Demonstration method. We're gonna copy the program again, enter our new menu item and then code the file input method. So when we test the program, we're gonna look for three things we're gonna look that make sure that opens the file, okay, that the file is indeed there will get an error message. If it's not, we'll look to see that it echoes the contents of the file correctly. And then our third condition is to make sure that that count is equal to three. So let's go ahead and jump onto our windows machine and look at the hands on example of this, and I'll see you on the other side when a jump on machine. Okay, now I'm back on my Windows machine here and let's go ahead and will copy the Chapter 16 directory to the Chapter 17 directory. So ch 16 Chapter 16 to Chapter 17. We'll go ahead and select directory and there we go. Now we'll change our directory to the Chapter 17 and we'll go ahead and load up program not CS, okay? I went ahead and made the modifications to this file, and hopefully everything goes OK, so we're gonna add in a new selection here, Selection four for our file input demo. And if I scroll on down, then I'm going to see no, my case statement here for my file and put demo. So its case number four. And this time I included the break statement, so I didn't forget that. And now if I scroll on down, I look at the file input demo method. So this is what we looked at earlier in this lesson. So again, we have our counter variable and are temporary variable for our line that we're reading in As we're processing the file again, we're using String reader system dot io dot stream reader. And we're reading from our file that we created in the last lesson, and we're reading until we hit into file or are null conditions. So we'll go ahead and write that line out, increment or counter, and then we're gonna close are filed. I should note that if a file variable goes out of scope So an example being out of scope is that it will return from this method, and that file variable goes out of scope. Dot net will automatically close the file, but it's really best practice to include the clothes method and where it needs to be. So you shouldn't depend on dot net Doing that garbage collection for you really should close those files and then our last line is the system that console that right line. We're writing out the number of lines in the file and noticed the syntax here with the curly braces in the zero in it that's gonna print out an energy value. And it indicates that this variable the counter is being processed and being substituted in with curly braces is so it's another notation that you can use for right line. So let's go ahead. I've got a terminal window open here and I'm I'm down. I noticed I've already changed to my C s code ch 17 or Chapter 17 Directory And let's go ahead and give this a run and make sure everything works. OK, so I'm gonna type in dot net run like we've been doing, and then I'm going to select item number four. So with any luck, we see our first line, second line and third line being echoed out. And it properly now says that they're three lines in the file. So writing more and mortar a demo program, just a couple of more sections that we're gonna look at for a demo program, and then we'll move on to something a little bit different. We'll change up the repetition a little bit when we get into some lessons a little bit later on. So that's really it. For this lesson, I'll go ahead and exit out of the program. Let's jump Actor are summary and wrap this lesson up in summary. We've now looked at how you can read data from a file and do a little bit of processing with it. We use some of the information from our previous chapters such a czar output file that we created in the chapter for this. So this is a really simple example, but a very common one. You're gonna find that you're gonna be opening files and reading them to initialize data, all different kinds of things as a fundamental operation that's very common in really any programming language, not just C sharp, so give it a Try yourself again. The instructions are included in the pdf file. Go ahead and keep building that demo program until you've completed all the functions here that really give you some hands on repetition in learning the language. I know it may seem trivial to keep adding to the demo program, but it really is the best way to get experience with programming. You've gotta write code. You've gotta practice. So that's it for this lesson. Thank you so much. I'll see you in the next lesson, but I 21. Chapter 18 Strings and Functions: Yeah. Hello, everyone. In this lesson, we're gonna look at strings and functions within the string library in C sharp. So let's go ahead and jump in and take a look. Strings air a common way to store most types of text data. So things like names, addresses anything that has a text in it. You can store in a string and operations on those strings. They're a very common operation and see sharp. The string library and the functions within it allow for really easy manipulation of strings. It's all built in, so let's take a look and see what the operations are you could do with some of these string operations. So some of the things that are very common you might change the case of a string. You might force it to all upper case or all lower case. You might look for certain characters for string matching operations, and those things were built in as well as character replacement, where you can replace one character with another character in one or more occurrences of that within a string. So what we're going to do in this program is we're going to create a short demonstration method and we're just gonna bundle in some of the more common operations within the string library so you can see how they work. So once again, we're going to make a copy of our program and we'll add another menu entry, and then we'll have a demonstration method to show off our string functions. So we're gonna be copying chapter 17 to Chapter 18 and then once again, we're gonna add a new menu entry. So in this case, it's gonna be selection number five for our string function demo. And then we're gonna have an entry into our case statement, just like we've been doing along the way. And this will be one of the last ones. I think there's one more that will be doing and Dimel breaking up into another separate demo program. But in any case, this is Case five for the string demonstration method. And once we put in, both of those pieces of a code will put in our string demo method itself. So we start off at the top of this method with a string that we're declaring called my String, and we're putting This is my string example into that initializing that data. So in 18.1, I'm just demonstrating how you can get this string length so you can use my string dot length. And we're assigning that to the integer value of energy variable of island, and then just printing that out. The next operation is converting a string to all uppercase, so work declaring a new string. And we're assigning the value of that of my string dot to upper. So that's how you access thes string methods is through the dot notation. And if you're in visual studio code, it will show you the available operations through that's through the intelligence. That's very helpful. So then, in the Converse and 18.3, then we're gonna look at a new string, and then we're gonna convert it to an all lower case variable in 18.4. We're looking with some of the sub string functions, and this one is starts with so you can call my string dot starts with and then put that into encapsulate that into the double quotes as faras the argument to that and in the world Trent return. True or false? If that sub string is if that string starts with that particular sub string. So in this case, it will drop through this logic and then execute in this case, it will imaginable. Say, the string starts with th in 18.5 were showing how to do a replacement here. And so we're going to replace any occurrences of s lower Case s with lower case X. And I should note that when you pass these arguments, they are case sensitive. And then in 18.6, we're just gonna pull out a sub string starting at the zero character, which is the first character through the 10th character. And then we're gonna pull that sub string out and printed out so pretty straightforward things. But I think coating this kind of reinforces the methods that are available and then also in the lab documentation. There's a link to Microsoft's documentation on the string libraries. He can read about even more functions that are included in the library. So the output from our demo This is the output that you're looking for once you code this up. So it's the string length is 25 years the all uppercase the lower case. The statement that saying that it does start with th and then the sub string operation. So pretty straightforward. So once again, we're gonna go ahead and jump onto our Windows program and I'll show you the steps here. We're gonna first copy the program at our new menu option in case statement, and then we're gonna coat our string demo method and, of course, compile and tested and make sure that the output is what you're expecting. So let's go ahead and jump onto our Windows machine and take a look at our string demo method and a little bit more about string functions. Okay, I've gone ahead and opened up a command prompt on my Windows machine, and I'm in my CS code directory, so I'm gonna go ahead and copy the chapter 17 directory to our chapter 18 directory, and once again it's gonna ask me if I want to do the whole directory and the answer is yes . Soon it'll change to our new directory and then I'll go ahead and open up visual studio could with our program dot CS file. Okay, I've gone ahead and drop the changes in, So let's go take a peek and just make sure everything looks OK, so here I've added in the right line statement for our new menu method and down below that , then I've put in a case statement toe handle that. So if I scroll on down here just a little bit, it will be case five and it should have a call then into our string demo methods. So here we see Case five. And I've had added that in as well as the call to the string demo method. And then here is the string demo method. Again, I just dropped it in a T end of the main method. But you could easily drop the Senate the end of the program as well. And here's the declaration of our string. We're calculating the length and printing it out in 18 point. To them, we're converting a string to upper case in 18.3 were converting it all lower case and then we're checking to see what characters the string starts with and showing the example of the dot starts with function. And then we're looking at a string replacement. So there again, we're replacing every occurrence of s with X, and then the sub string method is the last methods. So if I go down, I've gone ahead and opened up our terminal window here. And if I type in dot net run, our menu should come up provided everything's entered correctly. Looks like it compiled OK. Soon we're gonna hit a number selection number five for a string demo, and you can see now in the terminal that it's put out our output for the string demo as that we looked at earlier. So everything appears to be working. OK, so it's a pretty quick, uh, example here. It's not a ton of string functions, but it's some of the key ones, and you get the idea of how you can use these. You can look at the documentation back to Microsoft, their website and look at all the specifics, and there's just a ton of functionality built in. There really makes programming a lot easier having these functions available, so that's really good for this demonstration. Let's go ahead and jump back to our summary and wrap this lesson up In summary. We've looked at string manipulation functions within C sharp and again these air very common operations and computer programs, so odds are if there's a function that you need. If you look up in the string library, there's probably something that can help you out there, and you probably won't have to write your own function. So become familiar with those. Go ahead and look at the documentation. We put our own string demo method together, So now it's your turn of the attached instructions. Give you everything you need to go ahead and drop this function, and and while you're in there, take a look at some of the other functions and play around with those really save you some time to get familiar with the string library. This is a bread and butter of computer programming, so that's really if this lesson go ahead and give the lesson a shot and I'll see you in the next lesson. Thanks again. 22. Coding Exercise 3: Hello, everyone. In this lesson, we're gonna look at our third group of coding exercises. So let's go ahead and take a look at these. These are gonna be based on the last chapter that we looked at, which is Chapter 18 again, these are going to be simple, straightforward exercises that kind of give you some muscle memory. So you get some practice with actually implementing these string functions. So the first exercise is 3.1, and you're gonna right a C sharp program that reads in a string and prints out the length of that string. So if you look at the table below, if the input is this is my input string, it's going to calculate the length of that string, which in this case is 23 characters and print that out. So let's go ahead and look at the next one, which is exercise 3.2 and you're gonna right a C sharp program that prints out the first and last character of the input. So if you look at the table, the input string is this is my input strings. So the expected output the first character is an upper case T and the last character is a lower case G. And then in the last exercise, 3.3, you're gonna right a C sharp program that converts all of the characters of the input to upper case. So if the input on the left hand side is this is my input string, which is a mix of upper and lower case than the output would be. This is my input string all in uppercase. Pretty simple programs should not take you long to knock these out there again. Just go ahead and give these a try the solutions air contained in the attached pdf file along with the problem of statements as well. So you can download both of these. So that's really it for this lesson. Thanks again, and I'll see in the next lesson. 23. Chapter 19 Dates and Functions: Yeah. Hello, everyone. In this chapter, we're gonna look at dates and functions. So dates or one of the most common things that you'll use in computer programming in C. Sharp has a really rich built in library for handling all types of date function. So let's go ahead and jump in and take a look. So dates are a critical operation. There are all kinds of use cases and scenarios that you'll need dates with and computer programming. Some of the examples have included. Here are interest on payments, perhaps some kind of deadline for a process that that you need to monitor demographic information. So recording somebody's birthday that is a very common need and also its court of many operational applications. So looking at differences between dates, how many? How many days or minutes or seconds have elapsed since it began date and an end date in time? So those air just some of the examples. Let's look at some of specifics on how you can handle dates within C sharp. So the demonstration we're gonna put in a function much like we did in the previous chapter when we looked at string calculations, so we'll add a brand new method, and it will have a variety of what I think are some of the most common dating time functions that you'll use. So we'll calculate the day of the week will validate a date. Well, look at the difference between a date and we'll look at parsing all the components out of a date as well as printing it out in a particular format. So let's go ahead and take a look and see what some of that code might look like. So we're gonna do the same thing that we did in the previous chapters. We're gonna make a copy of our previous Chapter 18 code and moved a Chapter 19 and whether using Lennox or Windows have included that that command, which should be pretty familiar by now we've done it quite a bit. So we're gonna add our new method in, and I'm gonna go ahead and skip that part this time because we've done it a few times and we'll look at that code inside the demonstration where we're just adding another menu statement and another case statement again. That should be very routine by now. But we'll take a look at it when we look at the code. But now let's look at the date demo method that we're going to add. I've added some some numbered comments here, and let's go ahead and look through these. The 1st 1 is how to create a new date in time and so you can use it the new function, and you can pass it the year, the month in the day, and then it will create. In this case in my date, it will create the the date time instance, and I will note that in C Sharp, it's a date time data type. It contains a date component and a time components so you can do all kinds of things, and this example, we're just gonna look at the date functions. So we've created a new date time, and then if I want to print it out on a string, I conform at it with the two string method, and I can pass it a mask and that these masks have specific formats. So in this case, it's going to be the full month, the day, followed by a comma in the year and so this this format is common in the US but maybe not so common in other parts of the world. So you can manipulate that mask to change the format the way that's displayed in 19.3. Then I'm we're just looking at the month components. So, for example, for our date, we're gonna look at October, and it would. It would parse out just the month component of that by using the dot notation that dot month. Similarly, in 19.4, we can look at the day, day of the week and then day of the year. So a 19.4 we're looking at just the day component in 19.5. We're looking at the particular day of the week. So it would be Monday, Tuesday, Wednesday, Thursday, Friday. Whatever that falls on will be that day of the week. And then, um, we're gonna look at the day of the year, so that would be the American Day. Ah, in the year and then we're gonna create another instance here for a second date and time, and then we can calculate the difference between those two, and that's just a built in different so we can look a we can do a subtraction operation. And then we can convert that today's and you could convert that two months or weeks or other things as well. So very handy, all of this very powerful that it's built in. So let's go ahead and then look at our demonstration. We're gonna check to see what our output should be. We're gonna go ahead and make the coding changes and then once you run and then select the date demo function your ideas. Once you've dropped in your code, you should match this outputs. I've included that here for you as well. So let's go ahead and we'll jump into our Windows machine and we'll go ahead and copy our program. And then we'll add our new menu option in case statement, as we've done in our other demo code. And then we're gonna go ahead and drop in our date demo method, not compile the program, and they will verify the output that it matches What I just showed you previously. So let's go ahead and stop here and we'll jump on to the Windows machine and take a look at the code. Okay, so here we are, back on my windows machine here, and the first thing I'm going to do is copy our Chapter eight code Chapter 18 rather cut it to Chapter 19. So I'm going to use our ex copy command that we've been using. I'm gonna indicate that this is a directory. And now I'm gonna go ahead and change to our Chapter 19 directory, and we'll go ahead and open this up with visual studio code. And it's our usual program that CS file. Okay, I've gone ahead and drop the changes in and let's go ahead and review the code. So the first thing I did is I put in a menu option 64 are date function demo. So let's go ahead and scroll on down just a little bit. And now I've put in a case statement that handle that as well. So if that have done this correctly, I should have a case number six and it's our date demo function. I'm calling along with our break statements. So and a brief comment that explains that. And now I've also put in our date demo function, and this is the code that we talked about earlier. So now 19.1 is creating this new date time instance in and a variable called My Date. And then I'm parsing that out in a particular format, using the two string method next in 19.3. Then I'm looking at just some of the components of that. So I start with just the month component, the day component, the day of the week component and the day of the year. Very handy that these functions are built in and very easy to use. And now I create a second date variable, and I use that to calculate the difference by doing a subtraction and then converting that today's and I declare that that difference, then to be an integer variable or intent and then simply print that out. So that's our date demo methods. So let's go ahead and and go ahead and see if this runs. I've gone ahead and opened up, um, a terminal window down here and change to the correct directory, which is C s code C H 19. So I could just type in dot net run, and with any luck, it should spelled it wrong. So let's go ahead and correct that they put in dot net run and it should go ahead now and compile and execute, provided I put the code incorrectly. Seems like it's working. OK, so select items six, which is our demo method, and we're getting so many lines now in our demo, I'm going to scroll up a little bit so you can see that the date is October 23rd. The month component is 10. The day component is 23. Day of the week is Monday Day number 2 96 and the number of days in between those dates is five. So we're getting everything that we expected. So I'm going going to go ahead and select exit here and exit out of this. So that's a pretty simple demonstration of the date functions within dot net and how to use those. So let's go ahead and jump back to our summary and wrap this lesson up. In summary, we've looked at date calculations in C sharp and dot net again. Date calculations are very common in computer programs, and these types of functions that are built into the language really make it much easier to work with. So once again, we created a new method that encapsulated the date functions to kind of show off some of the more common functions and how you use them within C sharp. So we really got a chance to see data manipulation in action. So now it's your turn. I've included the pdf file along with this lesson, So you can go ahead and drop these functions into your own demo program. Make sure you're comfortable with how they work and take the chance to experiment with them and maybe add a few different methods in there. Other calculations so you can get familiar with the date library. So that's really it for this lesson. Thank you so much. Now see in the next lesson. 24. Coding Exercise 4: Hello, everyone. Now that we've done some date exercises, let's go ahead and look at then some further things weaken due to improve our skills with using these functions. So the following are coding exercises. This is our fourth group of coding exercises, and again, they're just designed to help you reinforce a C Schar statements that we just looked at to handle date function. So let's go ahead and take a look at each one of these. Exercise 4.1 is to write a C sharp program that prints out today's date and time in the long format. So if you look at the input on the left hand side, today's current dating time is the input in the expected output, and it shows you the example of what the long date format looks like. And this is a particular. The long format is prescribed in the C sharp documentation, so let's go ahead and look at the next exercise. Exercise 4.2 is to write a C sharp program that prints out the day of the week for the current date in time. Input again. On the left hand side is today's current dating time expected output. It's just the day of the week. In this case, it says the day of the week is Wednesday, but that will be whatever particular day of the week that you happen to run the program and using the current date and time on the computer. Exercise 4.3 then, is to write a C sharp program that prints out each element of today's date. You're just gonna break those out separately. So you're gonna print out the year, the month and the day separately, and then have it formatted with those particular strings. So very straightforward. Examples. The Solutions Air contained in an attach. Pdf. Go ahead and try toe again. Work through these on your own first, and if you get stuck, look at the solution files. But again, these are pretty simple examples. But the more that you do these, the more familiar you become with the date functions. And then when you have to write larger programs, you won't have to rely so much on memory since you've done these before. So that's really it for this exercise. Again, The solutions Aaron the Attach pdf. If you have any problems, then you can also reach out and contact me as well. Thanks again. I'll see in the next lesson 25. Class Summary: Congratulations. You've made it to the end of the course. You've done a fantastic job. First, I want to thank you very much for your interest in this course. I really do appreciate each and every student I have. Let's look at a few next steps that you might be able to take first off. Please leave a review if they're improvements you would like to see. Please include that information and be a specific as you can. I'm dedicated to making this course as best as it can possibly be. If you'd like to contact me directly, have included my email address at sales at Destin learning dot com. You can also find me on LinkedIn, and I've put that address out there as well. You can look for my other I t classes on you, Demi. I've got some or in the queue and some classes coming up soon. Also, good luck with your projects with C sharp and dot net. Thanks again for being with me in this course. Good luck in the future and I'll see you again soon. Bye bye