1 00:00:00,000 --> 00:00:09,005 [MUSIC] 2 00:00:09,005 --> 00:00:10,489 Hi I'm Jay McGavren, a web developer and teacher at Treehouse. 3 00:00:10,489 --> 00:00:15,170 And I'm here to introduce you to the C# programming language. 4 00:00:15,170 --> 00:00:19,823 We'll get into a detailed explanation of how C# works shortly. 5 00:00:19,823 --> 00:00:24,179 But that explanation will be a lot clearer if you've already tried a C# program. 6 00:00:24,179 --> 00:00:26,060 So let's run our first program now. 7 00:00:27,230 --> 00:00:29,959 If you're watching this video on the Treehouse site, 8 00:00:29,959 --> 00:00:33,238 there should be a Launch Workspace button on the page, click it. 9 00:00:33,238 --> 00:00:36,713 You'll see a dialogue where you can change the name of your new workspace or 10 00:00:36,713 --> 00:00:38,160 you can just keep the default. 11 00:00:41,716 --> 00:00:43,567 Click the Launch it button when you're ready. 12 00:00:46,910 --> 00:00:49,839 A new window will open with a Treehouse Workspace. 13 00:00:49,839 --> 00:00:52,120 Give it a minute to load. 14 00:00:52,120 --> 00:00:56,476 When it launches you'll see a sidebar on the left with several files including 15 00:00:56,476 --> 00:00:57,670 a Program.cs file. 16 00:00:59,080 --> 00:01:02,192 All the other files in the project are just there to support compiling and 17 00:01:02,192 --> 00:01:03,016 running our code. 18 00:01:03,016 --> 00:01:07,883 The only file we're interested in is this Program.cs which contains all the code for 19 00:01:07,883 --> 00:01:09,360 our program. 20 00:01:09,360 --> 00:01:13,455 Click on the file and it'll load in the text editor on the right. 21 00:01:13,455 --> 00:01:16,170 There's a lot going on in these eight lines of code. 22 00:01:16,170 --> 00:01:17,782 If you haven't programmed before, 23 00:01:17,782 --> 00:01:21,425 then there's some parts that you won't understand, but that's totally okay. 24 00:01:21,425 --> 00:01:25,798 For now, all you need to know is that most C# programs start out with code 25 00:01:25,798 --> 00:01:28,522 just like this, with a line that says class, 26 00:01:28,522 --> 00:01:31,759 a line that says static void main, etc., and so on. 27 00:01:31,759 --> 00:01:36,354 You don't even have to remember this syntax because C# comes with tools 28 00:01:36,354 --> 00:01:39,529 that can generate starter code like this for you. 29 00:01:39,529 --> 00:01:42,452 For right now the only part we're interested in is 30 00:01:42,452 --> 00:01:46,289 the code between these curly braces following static void main. 31 00:01:46,289 --> 00:01:50,030 This is the code that gets run when your program starts. 32 00:01:50,030 --> 00:01:53,489 The first line here isn't even part of the program code. 33 00:01:53,489 --> 00:01:57,298 Lines that start with two slashes like this are called comments and 34 00:01:57,298 --> 00:01:58,803 they're ignored by C#. 35 00:01:58,803 --> 00:02:02,310 They're only there for developers like you and me to read. 36 00:02:02,310 --> 00:02:05,784 The second line displays the text Hello World on the screen. 37 00:02:05,784 --> 00:02:07,326 That's all there is to it. 38 00:02:07,326 --> 00:02:10,910 This program is ready to run, so let's run it. 39 00:02:10,910 --> 00:02:12,883 Click in the console area at the bottom. 40 00:02:12,883 --> 00:02:16,390 You'll know it's been activated if a blinking cursor appears down there. 41 00:02:18,130 --> 00:02:21,550 Type dotnet, a space, and the word run. 42 00:02:23,616 --> 00:02:27,245 That will find and run our program, which prints out the message from our code. 43 00:02:30,181 --> 00:02:34,408 You can also click in the editor and change the message if you want. 44 00:02:34,408 --> 00:02:37,573 So I'm gonna change Hello World to my name, Hello Jay. 45 00:02:37,573 --> 00:02:41,574 Save your work by clicking in the File menu and choosing Save. 46 00:02:41,574 --> 00:02:47,368 Then you can click in the console again and rerun the program, dotnet space run. 47 00:02:50,051 --> 00:02:52,217 When you're done, you can close the window. 48 00:02:52,217 --> 00:02:56,500 Don't worry, your changes will be saved on the site's workspace's page. 49 00:02:56,500 --> 00:02:59,657 So that's what a simple C# program looks like, but 50 00:02:59,657 --> 00:03:02,465 C# can do a lot more than just say hello world. 51 00:03:02,465 --> 00:03:06,427 It's used to build popular products that you may have used yourself at some point. 52 00:03:06,427 --> 00:03:09,336 There's Stack Overflow, a website where people ask and 53 00:03:09,336 --> 00:03:11,526 answer software development questions. 54 00:03:11,526 --> 00:03:14,608 The Unity game engine supports building games in C#, 55 00:03:14,608 --> 00:03:17,340 including hits like Subnautica. 56 00:03:17,340 --> 00:03:19,095 The Visual Studio IDE, 57 00:03:19,095 --> 00:03:24,193 which many developers use to write C# code is itself written in C#. 58 00:03:24,193 --> 00:03:25,998 And these are just a few examples. 59 00:03:25,998 --> 00:03:30,269 If you want to write software that runs fast, but it's also easy to maintain, 60 00:03:30,269 --> 00:03:32,870 C# is a great programming language to choose.