Learn C# with CSharpFritz - Ep 1: Types, Type Conversion, and C# Language Syntax

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
good morning good afternoon good evening whatever time it might be where you are out there welcome back to my live stream this is a debut stream here on the visual studio channel my name is jeff fritz i go by the screen name c sharp fritz and we're going to spend some time today learning about c sharp this is the first of a very long series of videos of streams that you can participate in where we're going to go over we're going to get you started learning all about c-sharp this is intended to be a beginner-friendly talk radio like discussion you're going to find archives of this over on the youtube channel but we're going to broadcast live we're going to have our conversations right here on twitch now when i say beginner friendly that means we're not gonna talk about architecture we're not gonna talk about solid principles and dependency injection and the latest version of c sharp and all the cool new features that are coming out we'll eventually get to some of those topics that's not the tone that we want to go through as part of this show we want to talk about the things that help you get started we want to talk about basic concepts why would you choose c sharp what what does it give you what what are some of the features that i need to know just to get started writing and how can i get started writing what are what are the things that i need to install and and learn all about this great programming language that's available so i see a bunch of friends over there in the chat room already let me say hello to jean valjean 80 good morning to you um is that ozer sonal hello spined good to see you uh m pulaski hello shy sharp is here john callaway chris is that chris c119 nope sorry some of those commands that you normally find over on my twitch channel they're not running over here on the visual studio channel we'll eventually have a bot running here that gets you running gets you connected with all the features that interactive features that you might expect to see here on a twitch channel we'll get it loaded up we'll have we'll have the panels below configured and uh based on some of your feedback we'll build it out appropriately justin horner is here mstu for deca hello yokoso good to see you schwammy streams swami has look at this swami streams is saying it right here i do have i i don't see it here let me get it loaded up real quick um i do have featured chat running so we can take a look and and highlight some of the comments from folks that are here in the visual studio chat swami's got it right look at this if you're here you're about to learn c sharp from the right guy they name the no they didn't name the language after me no no i okay i get asked this question a bit i took the screen name c sharp fritz why'd you take that name so back in 2005 2006 um i started i was i i was a brash 20 something um writing code and for a small company and um i was doing things that i thought were were kind of breaking not just the project i was working on but i was i was breaking into new places i was doing things that were kind of out there um i was very much a believer in the alt.net movement and that was a movement of community folks around the dot net programming languages c sharp and visual basic that that believed hey there's other ways to do things besides the way microsoft prescribes things so i was doing things that were kind of outside the box so i started a blog called c sharp on the fritz right playing off of my name you see you see how that works there there was that was kind of a thing um um right where's that rim shot there it is so um when i so i have the blog and the blog is still out there if you go to csharpfritz.com that's my blog it's been around for 15 years um and when i when i took that and i wanted to go to twitter that was too long of a name so i dropped the on and the duh and it just became c sharp fritz and it very much became a brand that i used a whole bunch of different places including github youtube um tick tock tick tock that's a thing but i there's nothing on my tick tock i have a tick tock but there's nothing over there uh let me see here um good morning m stew justin horner freckberg good to see you i see some friends here void rose can more experienced programmers benefit from this um perhaps we're not going to get to some of that content today that you're going to benefit that experienced programmers would benefit from um but we're going to have fun we're gonna learn together um and this is intended to be talk radio format i'm i'm not sitting here um looking to to answer in lecture the entire time this is intended to be interactive and i think you're going to see from how i'm structuring the content and how we deliver the content and how you can access the content after this video is over you're going to be able to interact and and learn and have all of all of the materials available to you not to mention um as we're going along here you're going to be able to click through and try it out try some of the things that we're doing so this is the first of a very long series that's right uh aps twitch that's right we're um these will be archived over on i believe it'll be on the dotnet uh youtube channel not the visual studio youtube channel i have specifics for you and announcements and links through from we we have a show github repository i'll i'll show you where that is and we'll um we'll move forward and have a really good time together it look at this it's beautiful and sunny out there in philadelphia today can you believe it looking outside the i'm i'm stuck in the machine here as it were but outside in philadelphia it looks amazing so i hope you stick around i hope you have a good time um we're going to be telling jokes and and um it always chat room the ama flag is on the ama tag is on the ask me anything tag please ask any questions you might have um but we want to make sure that they are on topic questions outside of it questions about the latest microsoft news questions about the latest version of visual studio if that's not the topic we're working on i'm not gonna i'm not gonna answer those questions but if we are if it is a question around what it is we're working on i'm happy to answer those questions along the way um digi says in germany it's summer too weather is too nice to work yeah you know what something to be said about being able to go outside and working outside and working remotely means i i could go outside and work out there it's just this is where the studio is here inside the machine you know what i'm saying i'm inside the machine as it were and and i need to stick around here so um okay i think uh uh i wanted to get some music playing what music could i play i'm gonna play harris heller's uh synth wave this is copyright copyright free music that you can play on your youtube channel you can play on your twitch channel um it's great background music that you can listen to that is uh free for anybody to use anywhere no license needed and uh it's kind of groovy tech focused and we'll have this running in the background um let's start somewhere down here here we go thank you very much to harris heller he runs the alpha gaming channel on youtube and harris heller here on twitch for making some of this cool music available see um uh natoki stuff not gonna answer that question that's right out that's outside of our content that we're gonna discuss so i wanna get you in i'm going to get you started i want to get you pointed in the right direction with net and that means we need to get you an install and we need to talk about why c sharp there's so many things that you can do with this great programming language buckle up friends get ready we're gonna go on a a tremendous um this is gonna be a tremendous series whole lot of content i'm planning out writing a lot of a lot of content before i publish it here i'm going to be doing a lot of prep work to make sure that we're very focused in our discussions that we have here on stream each one of these sessions will be about two hours when it gets over to the youtube channel it might be edited down a little bit we'll see how my friends at channel 9 help out as far as how much we're able to cut how much we're able to reuse and maybe we break out and put some of our questions out as as other short videos for folks access we'll see how it goes and a lot of this depends on you i'm going to be running the polls here on on twitch a lot um because i want to make sure that that i'm meeting your needs that that we're discussing getting things moving in the right direction for you how's it going there it's signalized good to see you focused on twitch says freckberg yes indeed yes indeed um is that blood blood blood was taken welcome um with a with a comment here and and this is something that i think is um kind of makes me a little depressed to hear someone ask i didn't know c sharp was still relevant oh it's very very relevant um there are millions of dot-net developers out there there are millions of applications deployed at enterprises at on some of the biggest internet sites that you've seen some of the biggest games that you've played run on c-sharp they're written with c-sharp the unity game engine is built with c-sharp folks use that to build games all the time right here on twitch and it's it's freely available for anybody to use anybody can get started with c sharp anybody can build with it you don't have to pay exorbitant license fees you don't have to pay runtime fees to anyone if you want to build and deploy a simple c-sharp application when you want to deploy though to some platforms those platforms may have a fee for their developers to get in use their software development kits and get started so depending on where you deploy to it may it may have a fee but if you want to build a web application if you want to build a desktop application you want to build a console application you want to build a service that runs behind the scenes you can do all of that completely free you want to deploy that out to a cloud service to a hosting provider you're going to have to pay those folks to be able to deploy and use their services but if you want to deploy a mobile application you're gonna have to pay the mobile providers to get listed and use their stores so there's a little bit of what you can and cannot do with c sharp it is very relevant in 2020 um the music that we're playing this is from this is from harris heller's synth wave royalty-free license free music that you can use right on spotify i am covering the language i'm going to be covering the c-sharp language we may at some point get into frameworks but our focus is i thanks thank you could download visual studio for mac um i'm not sure why that popped up let me get rid of some of these old ones here there we go all right so um let me see here a couple more questions and comments here um is that let me marrow nebu uh says hello from morocco well hello to you out there thank you so much for tuning in from morocco can we um can we have a real quick sound off where folks are from in the chat room let me know drop a line with with country region that you're dialing in from you're watching today um and uh highlight some of the places folks are connecting from um the toki stuff says vb is the one that isn't relevant there are a lot of folks using visual basic visual basic is an extremely stable language that that is not going to be changing significantly going forward it it's it's done it's feature complete and they'll be maintaining the language going forward you're going to continue to get great support for visual basic and you're going to be able to use it with net5 with net core with net framework and we'll talk about what each one of those things are it'll it'll still be available for you to use um we are talking about c sharp today um c-sharp is still being improved lots of investment into c-sharp to make sure that it is a modern and um it maintains as a modern and and very cool language for you to use um you you'd get into mono game if you weren't so in love with blazer says chris c119 well thank you appreciate the compliments on that um uh chrissy's from new jersey we've got tampa alberta canada denmark joining in west germany and europe very cool charlotte north dakota washington silicon valley pop in the cloud loves blazer i i like blazer pretty much too thank you so much utah is here marrakesh welcome in istanbul thank you so much for joining us uh ozer sonal good to see you ozer is that ozersonall82 let me know i want to make sure i pronounce all of your uh stream names your your screen names properly here northern virginia is where the giggles is very cool um we're not um from columbia but living in melbourne australia good evening to you sq uh sqsw ps let me know how to pronounce that netcodies is here uh haha top swag code haha i see what you did there yes visual basic is still very much relevant stockport in the uk blazer mr magoo good to see you bosnia and herzegovina welcome um in the netherlands we are just starting windward high from nigeria welcome thank you for tuning in from delhi is where diva 73 is very cool gosh i really appreciate everybody tuning in um uh nataki stuff no is that no toki stuff do i like f sharp yes i do i do like f sharp but i have a preference for c sharp i think for everybody when you start programming you're going to find programming languages that you like some that you don't like and some that just kind of fit like a glove with around your brain right david handmeyer hansen the the original author the inventor of ruby on rails refers to when he started writing ruby on rails it felt like a glove for his brain and and that's what c sharp really feels like to me it just fits right it fits with how i think and so i prefer c sharp i i've i've learned a little bit of f sharp i'd like to spend some more time learning f sharp i've learned python i've learned html javascript other programming languages and those are they're they're great they have their purposes they have their own strengths and weaknesses but for me i like c sharp um i do not want to see any kind of um the chat room i do not want to see any kind of uh [Music] competition between or or bragging about one programming language or framework versus another and ado pilot i am not answering questions that are off topic today we're staying focused on learning c-sharp and if you want to talk if you want to ask a question about that happy to cover that tomorrow on my stream you can find that over on the c sharp fritz channel right here on twitch so let's stay focused let's get into the giggles well that's that's one way to describe it that that's a little over the top a little bit over the top it's a nice programming language i'm thrilled to be able to to say that i work with some of the the incredibly smart people that build the programming language i mean some people they invent a programming language and they call it a day and they go wow that was really cool we built a programming language um but uh anders hausberg the gentleman who who invented c sharp he didn't stop at one he made four that's pretty impressive stuff when you think about that um we're not even gonna get into dot net for the desktop so we will we will get around all of these uh turbo pascal delphi c-sharp and typescript are the four programming languages that our friend anders halsberg wrote maybe at some point um i'm i'm sure we're gonna have some of the folks from from the c-sharp team from the dot-net team join us here um maybe we'll have uh anders join us at some point i the the folks that currently run the programming language gentleman named mads torgerson is the lead uh language designer for c sharp does a tremendous job he's he hangs out on on twitter you can find him um every now and again talking about some of the cool features that are coming along and you'll see mads giving presentations at big conferences like microsoft build and microsoft ignite introducing new features to the language it's signalized please don't continue with the bragging or i will have to um i will have to time you out okay um at some point at puji um lambda expressions will be covered we're not going to get anywhere close to that today we're going to start at the very very beginning we're going to get well let's get over to the code let's go head over to what that looks like and we can start we can start looking at this is the website that you get to when you navigate to dot.net this is the place to get all allthings.net so if you go to that url i just dropped in chat you'll be able to get some information about how to get started right you'll get here and all the cool things that you can do with dot net free cross platform open source but france you're talking to me about c sharp why dot net okay here's here's the thing there's there's a framework there's a runtime and then there's a programming language okay so the programming language we're going to be using for this is c sharp there are other programming languages that are part of the dot-net platform and that can target the.net platform but when you compile your c-sharp code it turns into code that works on a dot-net runtime and that runtime runs on all kinds of different places like you see here it can run for the web mobile devices desktop you can build microservices with the runtime internet of things cloud applications machine learning development all these different run times and different frameworks that are available that you're programming content right you're going to write a program that uses a framework that will compile down and run on one of these runtimes on those target locations so that's pretty that's pretty cool right that's a lot of different places that you can go with it now i see some pretty good questions in here that are leaning towards where i want to go um so no toki stuff asks what's the difference between mono and net you might hear it referred to as mono as well so um when when dot net was originally released back in 2001 um it was made available from microsoft as a windows only unified application development um series of tools and um a fellow named miguel diakaza wanted to take that series of tools that were made available as standards and and take those standards and re-implement them on linux and um that's what the mono project was was the re-implementation of net on linux using effectively a clean room approach right did not have any of the source code wrote it all from hand to adhere to the specification that was published so re-implementing the c-sharp compiler re-implementing all of the framework things that you needed to write to a console to listen to a web request to interact with the network to write files to disk all these things that you need to do with the programming language and as time advanced and things changed and and the industry and technologies change it became clear that mono had a really interesting place where you could compile things and get it running on a mobile device on an iphone on an android phone and and the mono open source framework remained out there and they started building libraries on top of it frameworks on top of it that eventually became xamarin for ios and xamarin for android so mono is the free open source implementation of net that compiles within ahead of time um approach right an ahead of time um technique where everything that you compile gets all the way compiled down to assembly right it'll run natively on the machine where dot net code that you compile will run on top of a runtime that hands off the operating instructions to the pc so mono is being used by the folks at unity it's being used behind the scenes in xamarin it's being used um as part of the blazer project and the blazer framework to run on top of webassembly so that's a little bit of the difference between runtimes frameworks and the programming language and how we get into dot-net here so let me continue scrolling through some of these questions that we have here voidrose asks another valid question here let's bring this up house.net support in linux so since 2015 um the folks from microsoft in in coordination with the.net foundation um have been working on a version of net frameworks called net core and net core runs natively on windows mac and linux so you have very very good support for net to build web applications um console applications services on linux there is not currently support from the.net foundation for desktop application support on linux that's something that we're looking for help from the linux communities to help build that user interface framework so that it can be done um but there are some ways to do that with xamarin forms and get it running on mac and linux as well so um thank you for the question voidrose appreciate that but that's that will get you into dot net core um you can make iot projects that run on raspberry pi yep absolutely all right um a deal 518 this is a good question as well let's talk about this what are some of the prerequisites to learn c sharp for this series of videos for for this um for this stream series i have no prerequisites for you you don't have to install anything you don't have to go and learn something we're going to talk through everything at a very beginner level and give you some resources here on the web that you can interact with and build c sharp code to learn a little bit about it without installing a thing we'll get to a point where you're going to um you're going to want to install some tools locally because we're going to get into building some of these types of projects um and you're going to want to have a little bit more control running locally for those and there are other tools and features out there that allow you to build and do more um let you build and do more um inside the browser thinking particularly of code spaces you can work with more on that as it develops over the next few months that's not a tool that we're going to discuss um here all right a little bit of tea getting going here um hey how's it going there uh black eye good to see you and roosh um let's talk about unit testing frameworks on on my channel i want to stay beginner focused on uh on c sharp here all right so um so i just went to dot.net and there's all kinds of information here about all the things that you can use and some of the some of the customers out there that are using it and um there are around um some of these some of the enterprises that use net a lot of enterprises that use net they don't like disclosing their technology stack um they see it as proprietary and uh proprietary information that they want to protect they and uh that's okay that's their choice nobody says you have to go and declare here's what i'm using but there are some folks that don't like to do that so all right you can download here to jump right in and download tools to get you started i'm going to click over here to the get started and there's some great videos that are available for you to download download tools get it installed on your machine that's great um whether you're on windows linux or mac os you can click through and the dot net core 101 series is here from my friends uh scott hanselman and kendra havens you're welcome to watch that um but we want to we want to talk about and get get some discussion going on here and be able to talk about some of these things so i'm not going to be going down the hello world in 10 minutes discussion here i'm going to be doing everything in the browser with you um you're welcome to download if you'd like i mean you can download here you don't need to install a big um integrated development environment you don't need to install visual studio visual studio for mac you don't need to install visual studio code if you don't want to you can it'll make you very productive because there's all kinds of enhancement tools in there to make your editing experience amazing but you can run on the command line you can download just the sdk right here for net core to get started now there are different frameworks available right dotnetcore.netframework.net framework is the version of dotnet that's been around um since 2001 so almost 20 years and runs only on windows for new applications we encourage folks to use net core that'll allow you to build for windows mac and linux compile and put things inside of a docker container it'll also let you build web services web applications um system services it'll let you build desktop applications for windows using windows forms or wpf the windows presentation foundation frameworks so you have a lot of different options between these two just to get started so we encourage you to try net core if you want to go through and download but for the purposes of this we're going to go through and we're actually going to do work in the browser using something called.net interactive and that's going to allow us to use jupyter notebooks to write some documentation write some code let them interact with each other try some things out without breaking anything without being wrapped up in all the formal nonsense of building a project and building an application so um should be real easy for us to get started we can talk more about installing and managing the sdk another time i want to get in and talk about get right into nuts and bolts and get started with some of this get started writing writing some simple code all right chat room so all right just looking here dot net core doesn't work for you why doesn't it work with you for you let's go let's do this so i have a i have a github um i'm known for dyeing my beard funny colors um that was a drawing from my friend um he's reverent geek out on twitter that is david oh my gosh i'm blanking on david's last name he's reverend geek on twitter he is oh my gosh and um i'm blanking on it my apologies uh david neal thank you swami um and did a drawing i had a purple beard for the visual studio 2019 launch purple is more my color well thank you it's very kind um so if you go to my github github.com c sharp fritz here is where you're going to find our um our show repository that we're going to go through here c-sharp with c-sharp fritz click into there and this is where you're going to find all the source code there's the link for you all the source code all the notes um i'm even going to build out an faq here as we go along but you're gonna be able to get started in your browser with some of the content that we've built and we have here now i've configured and i'm running this with jupyter notebooks and i've already got a jupiter notebook running locally here if you want to jump in you want to check out the notebooks i'm they're inside this folder and you can download and run this if you have jupyter notebooks and net interactive running locally i don't want you to go and install that locally if you don't already have it but if you do want to run it you do want to follow along you can click launch binder here and it will open up using the binder web application and run right in your browser so this is going to start up and eventually everybody will be able to jump in and you'll be able to see exactly what's going on with this first notebook that i've built to get us pointed in the right direction get us started um i i've started a wiki page here and we will build this out like i said here's a faq as as more questions come up that are that we frequently have i'll get them loaded into here so you have something to reference going forward if there's any issues if they're when we get into our sample projects if if we put some stuff out there and you want to suggest features we'll have issues and pull requests that we'll get into at a later time so for right now i want to show you where i started with this first jupiter notebook this is using jupiter lab it's a way for you to interact with and like i said write a little bit of markdown write a little bit of code and have it interact john callaway is here good to see you um a couple more questions here folks interested in the cap um this is a cap with the visual studio icon on it that i made for the visual studio 2019 launch um this is not available from the folks at microsoft this is um literally i went to my local embroidery shop and had them make a hat and what's what's important is you see you gotta wear the hat because it gets a little blue underneath here right yeah so keep the lid on right keep the blue in check all right um so uh wandy says microsoft should make visual studio hats i kind of agree with you um but it's not my decision we we have um strongly encouraged the folks in the marketing department hey we really like to we'd really like some of that but so um yes you do need the sdk and the runtime for an application to run but if you install that if you download the sdk to the question in chat if you download the.net core sdk it will install the runtime for you as well so i see a couple folks saying that they would that they would absolutely be interested in buying one very cool and friends um if you please if if there's things that you want to remember if there's video parts of what's going on here that that you want to be able to share on social media hit that clip button there's a little clip button right over here it's right next to the closed captioning button click that and um feel free to make clips share it on social media about what's going on here let the world know that we're having some fun learning about c sharp together all right let me go back over so if you've opened up if you've clicked through binder you should have a document that looks like this when you click into the notebooks folder and right so there's a launcher here you can build your own notebooks if you'd like but um if you click into the notebooks folder here's the first one called zero one zero one so um it's the first month it's the first session that we're doing and i and i'm just calling it first session for today and here's the tab with the content that we're gonna be talking about now we've already had some folks ask questions that that i i was going to describe and answer in the first paragraph or two here in this first section ah look at that it's like i knew you were gonna ask those things and i already loaded them up there right we already had a question about mono there it is and about what a dot net framework so windows forms asp.net xamarin for ios blazer those are various frameworks that you can build towards and use with c-sharp okay i i want to write some code let's get into writing some code i want to write some code let's do this let's get in and and get started let's let's break some things you know what i'm saying um let me pull down the music just a smidge there we go because darn it i want you to be able to hear some of those funny sound effects all right so it made yeah it may take a little bit where oh yeah right and that's that's one of the things that i want to make sure you're comfortable about here as we're going along is by doing some things in the browser like this we're going to break things absolutely and we don't care okay it broke no harm no foul it didn't crash our machine it didn't um nobody's nobody's information got lost we didn't hit anybody's credit card or anything it's just in the browser who cares this is taking a little bit to launch if you're out there but it will eventually pop up and you didn't dox yourself thank you mr smoofy that's the important thing don't dox yourself learn from me and don't doctor yourself because i tend to do it a bit just a bit it happens every now and again and you don't want to do that okay there you go and from here you can click into that first jupiter notebook and it'll open it won't look quite the same because it's in the jupiter notebook interface but uh i'm over here running locally with jupiter lab and you see i'm running locally any changes that we make any additional code that we write here i will save and i will update and they'll be available in the uh in the github repository and eventually the notebook that's running out there will be updated with um because it has a build cycle it goes through will be updated with that additional content so if you're watching the recording this will be updated and it's it probably doesn't look like this anymore because we've added some additional stuff later in the session okay we're going to talk about types keywords and operators today i'm going to get you in and get you familiar with a little bit of just the basics just enough to get you going okay this isn't too bad i know what's going on here so we we already had this discussion about what c sharp is what you do need to know is that when you write a typical c sharp program you need to define how that programming language how the framework it interacts with and any other references that you may want to bring in references that let you interact with the web or or some other service or maybe you've written some business logic that that you want to put into a different program be able to reference and consume that you're going to need to define a project file when you see project files in other programming languages you see right you see a package.json file with node in javascript right and you see other other files out there that describe how to compile how to structure your content they may call them a manifest um but it's basically the same thing in c sharp we'll create a cs proj file um i double clicked on that and i shouldn't have we'll create a cs proj file right some project name dot cs proj and it'll contain all the things in it that describe how the project runs um for this i want to make sure you know what that is so that you don't get lost you don't see this thing ago i don't need that i'm writing c sharp content the cs proj file don't worry about it [Music] it you have tools that will help you manage that content and manage the structure of your application now most c files end with a dot cs extension let's write that in here let's make sure that we got that um all uh c sharp files um carry a dot cs right uh file extension by default okay there we go so dot cs for c sharp it is a file that contains c-sharp programmable content right it has some language content in there that you're going to work with now there are two or three rules right off the bat that you need to know about c-sharp syntax that that are really the rules of the road here there's a semicolon at the end of every statement statement there's things that are block level interactions that you might do an if statement that you might run into right an if block level um interaction a for loop you might write a while loop that go do these things and and repeat over it um those are different a statement a one-line statement assigning a variable um doing some calculation or something you need to put a semicolon at the end of those one-line statements um and tony davis with a with a comment here statically typed versus strongly typed these are statically typed this is a statically typed language um and you can get into and do some strongly typed things later we'll get into that but statically typed means that every variable every object that we interact with has a type there is some sort of a type right a type reference that it's going to use and we'll talk about types here in just a second so semicolons at the end of everyone comments real easy forward slash forward slash everything after that is a comment you see here and forward slash star use these slash asterisk fencing right everything between slash asterisk and asterisk slash across multiple lines are commented out they're not referenced the the compiler right that piece of that program that takes rc sharp code and turns it into a program ignores this it effectively throws that out and doesn't do anything with it okay now everything in c sharp is an object comments are not an object comments are ignored so if we get into and we start talking about objects in c-sharp this is an object-oriented statically typed language so we have types that we need that come by default with the language and i even linked off here to the documentation for built-in types for the c-sharp language and when you look at some of these built-in types they're just numbers ah boolean boolean is true false but byte uh signed byte character right a single character right those are letters and special characters that you might have on your keyboard uh decimal double float decimal double and float are those are real numbers right that have numbers after the decimal place um integer unsigned integer uh long unsigned long short unsigned short those are integral numbers they don't have values after the decimal those you're going to be able to go a lot larger in the number that you can store in those types and whether they're signed or unsigned you might be able to store negative numbers or positive numbers or just positive numbers depending on which one you use uh that's right is that is that mr fos is that how you pronounce that um they're all inheriting from system object that's right so there is and it's not listed here but there is a object type that all of these inherit from it's the base type for everything inside of c sharp is an object everything is an object so there is an object type that everything belongs to now that means that you can generically refer to everything as an object because everything descends from an object everything inherits from it we'll get into object inheritance probably in our next episode together so um ap aps twitch asks um about a jupiter lab how to interact um so when you're over here in the notebook if you double click um it'll turn into the markdown right and we're actually going to do a little bit of this um as we're going along and we get to some of the code that's in here so these are some of the built-in numeric types there are some other right these are also value types value types and reference types are two different ways that dot net stores things in memory okay value types are stored in what's called the stack and the stack is a very fast access area of memory reference types are stored on the heap and when they go on the heap it takes a little bit longer to interact with them for our human eyes you're not going to see a significant difference when you interact with them but all of these at some point get garbage collected you don't have to destroy these types you don't have to say i'm not using that anymore it will eventually be collected by a garbage collector when it sees that these things are no longer being referenced and the garbage collector will free up that memory there's a comment there's a question here from far too long um and this is a valid question why isn't c sharp compiled to native code directly instead of requiring a runtime on the target host it's what has always kept me off that language so you can compile it to native code there's a second step you can do the reason that initially.net went um and compiled just to what they call um intermediate language right which is a way for you to build code that will run in a bunch of different places wherever the net runtimes are installed and that's what far too long is referencing um and that means you end up with a much smaller deployment you don't have to deploy tons and tons of things because you're not carrying all of these things that already run but initially it was just on windows everywhere um there are there are options to what do what we call engine to native generate code and it'll actually compile with that native code and make that entirely available to you you can do that with net framework with net core you can publish and deliver those pieces of the framework that are appropriate the run time for that target operating system you might be sending things to and and you can do compile directly to that native code with um with xamarin as well and you're going to see a little bit of that start to happen with net 5 and when we start to cross and we bring together all these different.net technologies so it was intended as as a speed thing keep down the size of the application be able to deploy because everybody has net framework running dot net framework is a part of windows it'll always be on windows going forward so if you only need to build things that interact with the file system well there's already stuff to do that installed and running and native on windows so we can keep that a lot smaller without deploying those extra things and that was part of the decision behind that this is a very exciting time to be using.net lots happening lots growing and coming together and we we really feel like this is um a renaissance for net developers you're welcome far too long thank you for the question very much appreciate questions coming in from from the viewers and we want to make sure we answer your questions oh that's some good tea all right so those were our value types we have reference types right there there's our object and there's a string a string is a reference type because a string is actually made up of a collection of characters right and that collection we call an array right an array is just a one-dimensional matrix it's a one-dimensional collection of characters there's also dynamic dynamic is a is a funny thing in the c-sharp language we're not going to get into dynamic for a bit here but know that you can create a dynamic object a dynamic type and interact with it but for getting started we're going to put dynamic to the side and we're not going to talk about it yet we may talk about it in a few weeks it's not something we need to get into let's stick with just these static types and get into these so all right so we can declare our variables like we now you see each one of these things here with the number next to it the this is code running inside the jupyter notebook and you're welcome to click into it and change this we declare our variable types with the type in front right we declare our variables with the variable type first and then the name of the variable so i created an integer a 32-bit integer that's what the int type is and you can go through the documentation and see the exact memory allocated for each one of those types and it's int i and great that that doesn't really do anything i can also create a a double right a double whatever um right i can create right character uh and whatever okay and if i tell it to output what that thing is there's nothing there you've declared a variable there it isn't anything in fact it has the initial value of zero we can initialize and set a value on that variable so we can not only declare the variable but set a value into it by using an equal statement at declaration time so int i equals 10 and i i put the variable on a line by itself and the jupiter notebook knows to output what that is so in i and right i didn't declare what it is by default it's zero if i change this to j and i run that j is zero as well uh if i look at the character the character is just the empty string there's nothing there nope we're not getting into dynamic well caprina we will get into that a little bit later type casting we can talk about typecasting that's probably a good good thing to talk about here so um let's get to typecasting i'm gonna i want to pin that topic we'll get back to it um let's jump into that um right here we'll we'll talk about typecasting right there and i'll write some content to go with that and uh we'll write some code and just drop it in here um okay so real uh oh the var keyword was next so right we declared things with int double car those various types well if you're assigning a type you don't have to go and specify here's the type that i'm defining each time you can use the var keyword for a little bit of syntactic sugar it's not required but when you use the var keyword like i am here it tells the compiler go figure out what the what the type is that's being assigned on the right side and that's the variable type of this thing here okay and you don't have to make your variables one character name right you can make them as long as you'd like and reference them elsewhere in your program um caparino didn't know python can execute c sharp code well this is a jupiter notebook running dotnet interactive for those of you that might be interested um dotnet interactive so this is running a no this is running a kernel um behind the scenes and you can install these into your uh into your jupyter notebook configuration so that it runs not just python but it runs other programming languages other tools other visualizers so that you can use more than just python with a jupiter notebook so you can learn more about how that's configured right there with that link to the dotnet interactive project so var lets the compiler infer the type versus the explicit declaration that's right tony um so i'm explicitly declaring it here if i use var the compiler will infer it and compile and we'll put the appropriate type in the code that it generates right it does a little bit of look ahead so you're not actually um there is no performance hit for using var versus int it's strictly a preference it's strictly we call it syntactic sugar it makes your coding experience a little bit easier um wandy says var is dangerous it's always best to be explicit if possible it's optional you folks can choose to use it you can actually set up um various editors to indicate whether var is allowed or not allowed in your source code you can have it you can have it raise an error right it says sorry we don't allow var in our source code i like varm because i think it's something that makes it very flexible when i'm declaring my types um and the compiler will find if there's a if there's a bad type reference later so it is a preference all of this is about is about freedom to choose how you want to interact with your code similarly um space can be freely used throughout your c-sharp program you don't have to always have the same number of spaces before these i can i can put spaces there i can put tabs it doesn't matter it all works okay so um you have options you have freedom to choose and run your code write your code so that it it looks the way you want to um a company i used to work for we would define our our variables um so here's maybe bar i equals 10 var some really long variable name equals uh i don't know nine doesn't matter but we would see that and in order to make it look a little bit nicer we would add some space in here so that these all lined up and you could look down and see there's my variable names on the left and all my variable assignments initialization values were lined up with equal statements nicely in my code and that's okay that works just fine right i'm hitting control enter after i click in here and update some code you can see karnak in the top left corner is showing you what keys i click i type to affect my interactions here so um let me go back up here into in syntax 101 comment syntax um everything in c sharp um let's also put in here um syntax 101 and let me also put in here a quick statement um uh c sharp is not uh space sensitive um and we also should know c sharp um is case sensitive okay and i'll i'll add some text around that later so right we named our variables i j and c here int i equals 10. it is case sensitive if i try to reference i here i i doesn't exist right it needs to be the same casing right so some really long variable name here right um down here some really in it do i get there you go even get type of head completion in right there you go and it shows nine so you need to make sure you have the correct casing right if if i get that wrong that doesn't exist so type ahead right the the type ahead feature right i'm i'm hitting tab and it's letting me um right uh tab it's automatically completing it for me i hit enter and it completes it here in the jupyter notebook in other editors visual studio code visual studio rider um your choice right the accelerator keys to activate the type ahead completion may be different so let me take a look there um [Music] tony davis finds var increasing signal to noise um it's easier to read okay um shouldn't you write code snippets as you would write code well we're not talking about code snippets today so um no we're not going to talk about that moshiko that is way complicated we're not getting into into efficiency and complicity today we want to stay simple this is for beginners next is this concept of real literals and this is something that folks actually folks forget folks don't use that frequently so there are suffixes you can put behind numbers d f or m that will force a number to be either a double a float or a decimal right the d is already taken by decimal so they move to m and m is the decimal way to reference that so um every variable every variable is an object so even though i've declared this number is 4d i'm saying hey this is the number four but make it a double i can put a method at the end of that variable reference dot get type get the type for this and because i don't have anything around it jupyter notebooks is going to report what that type is so 4d is a double if i change this to an f and i run that now it says single it's a float of single precision okay and if i change this to an m it's a decimal okay so it's it's coercing it's the coercing that type it's figuring out and interpreting here's the code that's on the right side of that assignment and and we're explicitly saying that 4 is a decimal with the the suffix of an m turn that into turn that number variable into a decimal physitronic with a question when you use var does it behave like a global variable in javascript so um global variables like you have in javascript are are within the scope of the page right or the scope of um the application that they're running within we're going to talk about scopes as we get into classes and interfaces i think that's going to be next week we're going to do classes and interfaces we'll talk about that the var is private to the block that it's in notice i said block not method but within you can also have var run within within an if block within a four block or a while block those block level statements that say here's a collection of code that i want you to execute in this scenario within there you can run a var and it's only within that scope it's only available inside that block or in a method a method is a block as well if you declare it inside the method it's only available inside the method and we can create variables outside of there that do have wider scope that are more easily available across our entire application thank you for the question fizz physitronic appreciate that that's right sir johnston purely syntactic sugar you don't need to use it it doesn't it doesn't do anything special for the machine it doesn't trigger some secret method that runs behind the scenes no no it's just there for humans to be able to read and see oh here's my here's my variable declarations var var var var var because if i did make these right if i did make these a little bit more than than var right um if i had in here um string foo right and i'm gonna use spaces to right and this is uh something over here well now everything that i did to try and get this lined up isn't lined up over here also right and you can use string like that but right now if i want to get everything lined up now i gotta write put some of these over here and something like this and put this and you could do that that might be nice that may work well for you but right oops oops fat fingers right that looks really nice right and it's strictly syntactic sugar foo and bars some of the worst things that happened in programming yeah can you call vars over the scope asks moshiko i'm not sure what you mean by vars over the scope if you declare scope for something you need to declare the type explicitly we'll get into that we'll get into that but i'm right now i just want to declare variables within with within a little bit of a little bit of interaction with variables here inside of the jupyter notebook we'll talk about scope later like i said scopes clap classes interfaces we'll talk about those next time um would i advise the use of wandi asks would i advise the use of var over specific data type i prefer the use of var over specific data type you don't have to it's strictly a preference just like spaces versus tabs strictly a preference use what makes you happy your choice um i see moshiko asks clarifying about if i have a var within one scope and you're inside of some other scope can you bounce back and forth no var is private to that area that that block that it's been declared in can't be accessed outside of it hey excite good to see you um physitronic we will talk about innumerable in the future yes um yes tech team 12 you can use uh c-sharp in jupiter labs so um will the notes be on github yes there we have a repository for the show that'll always be updated that we are going to fill out you can get to the notebook there you can click to launch the binder right there and you can get into the jupiter notebook there's instructions on the net interactive page i should put an entry here um let me take that as a line item here let's add some notes um add reference to dot net interactive um add links to the readme for information about getting started with net interactive and jupyter notebooks jupiter the the whole dot net interactive thing um this is documentation um yeah i'll just leave it like that the the jupiter notebooks.net interactive this was a project that my friend maria nagaga spent a lot of time working on to to get across make sure that it was easier for folks to teach and interact with um dotnet without installing anything right you can do this on your tablet you can do this on your phone if you'd like if you're doing it on if you're doing it on your phone i suggest getting a bluetooth keyboard wire up to your phone so you can do that you could do that and it'd be really cool um yes this is a very new series um el lehmann um it'll all be available on the dotnet youtube channel uh later on you had an introduction algorithms course and you never used the var keyword var was introduced i thought it was dot net three five that was about 2008 that was introduced um so it's been around visitronic yes my keyboard does have um it has cherry blue switches in it yep um any preference to jupiter lab over link pad i can do it in the browser and deploy these and make them available for anybody to interact with when i'm done with with what we're working on here on my local copy of this i'll add some more text to this and i will update the publicly available notebook for anybody to be able to interact with and particularly those of you out there that are watching on youtube you're going to see the publicly available version of the notebook um updated with all the content here that we finished during this session okay good next steps so let's talk about um type casting and um i'll have to add some text here around what type casting is so i'm going to open a block here and let's let's talk about casting things from from one type to another right um if i have an integer right that which is a whole number and i want to make it into a decimal because i want to be able to i want to be able to divide right i'm going to have some decimal remainder on it or um right i want to i want to take a number and turn it into a string right i created a string here by including enclosing that in quotes i can i also write i can make a um let's do it down here ah no um i created a character c here um let me see let's add another block no no no um right if i create a character right you can set a character right string is in double quotes you can set a character with a single quote and that will allocate that character all right [Music] let's say display right and there we go nine displayed that display is a is a feature of the jupiter notebook kernel to display some value and c is the character c i can't put multiple characters in here um right i can't like that doesn't work too many characters in a character a liberal a character is one character okay and you enclose it in single quotes single quotes double quotes are very important in um in c sharp the youtube channel is youtube.com it that is dotnet d-o-t-n-e-t you'll find it over there when we publish you can define an ink by a decimal and by put that result and define it well hang on let's let's talk about that there you go right um so if we have an integer right um [Music] right uh let's call this value a right and we make this 10 right um if we have another integer and we call this value b and we make this um 5 right um no hang on if i want to take 10 and turn it into a decimal right um let's call this value b right i would i can assign by doing something like that but i'm not going to get the same thing out of it it's 10 but it's kind of forcing its way over there if i go the other way around right it's kind of forcing interpreting and saying well i can make that into a decimal but there's also size limits to these if i turn this around the other way you can't convert a decimal to an integer because it has leftovers right it's got things to the right of the decimal place so it doesn't know what to do with that you can force the issue to convert by putting inside a parentheses before it the name of the type you want it you want the compiler to convert to i'm saying hey i want to force i want to explicitly convert from an integer to a decimal now right let me let's put another right let's do that again the other way around here right int and we'll make these down here value c and value d okay i didn't spell display right did i um right and if i do that interaction it it works but if i let's copy this so you've got both of these lines here um force the conversion of the value c to int with the right int markup modifier let's call it right so there you go you can't explicitly do that conversion but do it that way it does work all right so this is called up here where it's able to say uh that's supposed to be a decimal um [Music] right um i need to rerun yep um this is called implicit conversion because decimal can be implied it can be implicitly converted okay yep value d isn't declared good so it this is implicit conversion here let's not call this let's say explicitly convert value c to integer with the int modifier right um so if i do that that works okay um this errors out because um int cannot be uh implicitly converted to by a decimal now there are some constraints on that if i if i have an integer that is bigger than a decimal allows you're not going to be able to do that conversion right take a look back here at the built-in types there's decimal there's integer right decimal goes to um it has negative 10 to the negative 28th to 10 to the positive 28th that's a really big number integer what is that um right 2 to the 32nd it only goes to 2 billion so if i try and put a decimal into an integer that's bigger than that you're going to get an error right you can't do that right so let me go back down there right so if i say not 10 right it's bigger than 2 billion so there's a thousand million billion right there's trillion that doesn't work that's too big okay you can't that's bigger than an integer you can't stuff it in there all right so you're not allowed to do that interaction there it goes so you can cast you can force the cast between these different types and these are the the built-in types eventually we're going to have our own types and we're going to want to declare well how do you do that implicit conversion how do i do that explicit conversion what does that look like and we're going to be able to define that in our own types later and we'll we'll be sure to cover that next time i need to keep a notepad here of what i'm looking at what i'm promising i'm going to be talking about next time you know what i'm saying here friends right next time we're doing classes interfaces um operator methods we're going to get into so we've only just been we've assigned things with the equal statement here what about other operators that you want to do right i mean you can do some of those basic arithmetic operators that you you kind of expect in in your in your programming language hey hey uh that one go away this one there we go so right if i have um right if i have some initial value let's not do that um right so uh right some maybe it's a number of apples and it's 100 apples and if we have another one here and it's the number of oranges and maybe it's 150 oranges um well i can i can clearly report my apples and oranges by adding them together like that okay fine um right now i can also say well how many more apples do i have than oranges right turn that into a minus fine that works um right multiply of course works right duh um divide is where it gets interesting that works because we're all integers but what if this is 30 i've got an integer divided by an integer the output is an integer it's not right the remainder as a decimal and this is where you may want to convert things and force it to be a decimal because now when i say the divisor is a decimal by putting that m suffix now i get a right and look at this if i put some parentheses around this and say give me the type of that it's a decimal for that output because the divisor is a decimal it takes that type and that's what it passes through dre1865 asks how long are you going to have these sessions these are going to be once a week um and i've actually got a frequently asked question item here we're going to be doing these regularly monday mornings at 1300 utc 9 a.m eastern 6 a.m pacific right here on the visual studio twitch channel and the recording will be available on the um net youtube channel and i'll add a um let's uh edit here um where are the recordings available um for 14 days after a um after a stream they're available on the twitch channel at uh twitch tv visual studio videos and will be archived um on the youtube channel at uh youtube.com.net i believe is where it is added uh links to archive videos you're gonna make me tab fine there you go all right and we'll keep adding out adding more here um and there's the link there you go all right so different things that we can do with the basic arithmetic operators right add subtract multiply divide but there's also there's also a modulus operator that you can use right so not only are we dividing getting three point whatever but we can also use the percent operator here and it will give us the remainder right 10. 100 divided by 30 is right it's three and one-third but the remainder is ten and that modulus operator comes in pretty handy when we wanna do things like well is this even or odd right if i mod 100 by two right that zero right but of course if this is 101 i get one because right there's one left over when you divide by two so it's an easy way to tell even or odd if it's a multiple of some number it'll come up as zero that's the modulus operator okay that's fine um you're right mr smoofy um we should include some links to the actual articles um in the documentation like i i did for the built-in types up here and hearing that feedback kind of confirms for me that i should include some of those um some of those links here um let's add links to the full uh docs microsoft.com article we can do that and i'll assign that to myself we'll get that taken care of that's a fine idea we'll have that updated and available inside these documents as we build and work with them i gotta keep an eye on my time i got about 20-25 minutes left that's right beldaphus you can run.net on jupiter so there is a dotnet kernel that you can install using the.net interactive project um so so basic arithmetic operators that's fine we can also use the double equals operator right equals is the assignment operator we can use double equals to test if something is equal right i can say apple's double equals 100 false it is not 100 it's the boolean false value returned is it 101 yes true i can use the um i can use less than right less than and in those values right to further test i can say less than or equal nope i can use greater than or equal and i can also use greater than the does not equal operator is exclamation point equals to get the does not equal there is no triple equals operator that doesn't exist that's not a thing in c sharp like it is in other programming languages so um now this is doing strictly a value comparison it's comparing the value of that there's other things where you can compare references that's a different topic about reference how you reference types and how you compare those things you may want to compare and say well is this object equal to the same as that other object so don't want to get don't want to confuse things immediately here now we can also use increment operators i could say apple's plus equals 10. now plus equals says add this value and assign it to apples so 101 plus 10 is going to be 111 and assign that my value is 111. so it assigns end increments all in one shot i can do the same with minus and i'll get 91. i'm just now realizing that i should be like duping these off right i should be doing something like um see put that there back over here no right yeah i need no not that one this one i need semis at the end of this there it goes right now this is actually retaining that value it added 10 and went from 101 to 111 i took 10 off and now it's down to 101 okay you can also multiply i don't see too many people do the multiply equals right but that's absolutely a thing right i mean that's kind of weird but can be done same thing with divide equals right that can be a little strange as well [Music] um um see i'm trying to divide and assign a decimal value back into the integer you need to be careful around that so if i start this off as a decimal up there well now it works because i went from right 1010 to 101. if i change this to like three now i get a funny number there at the end so these are different ways that you can run and test this beldathus with an interesting question sure let's let's talk about that and that's something you can certainly experiment with here is the decimal 30.0 equal to the integer 30 let's find out right 30.0 equals 30 right is it yes yes it is now operators can be overridden and behave differently between these two these are value types the integer and the decimal so they know right 30.0 right it's it knows that they can be coalesced they can be coerced that's what i'm looking for they can be coerced into the same type and those numbers are in fact equal right of course if i make this 30.01 it's not but because i've explicitly specified that it is right even if i put an m on the end there it is okay now what might be a little weird is one's a decimal one's a double and you can't test across them now if i force this they are because we've forced it into the same type so right that's interesting if i make that a double it works so there's right that that coercion that happens for numbers it works wondering how to get two outputs to display yeah the display method that you have here display command you can wrap it around some c sharp code and it will display that um i'm going to agree with sir johnston here that that's a good piece of advice here it's a bad idea to compare equality when non-integers are involved because there's limited precision when you get into double and single precision numbers right you're going to end up with some digits way at the end that are not quite precise that it might be a little tricky to interact with that's why i like to use decimal um when i need to have a fixed number of decimal places i don't want you to go and have some precision at the end i want decimal i want to be a little bit more precise yep double equals on a floating point number can get a little bit tricky so if you use decimal it forces the precision a little bit so those are some of the simple operators okay that you can interact with now you can extend and build other operators that you could work with that you could do things with um [Music] right because operators are another object that you can interact with now i'm going to go to my my show notes here that i forgot to open up and put on a screen and make sure that i got through all of the content that i wanted to today [Music] unfiled notes sessions yeah yeah i think i did i think i did get through them oh no no no oh gosh here we go let's get in there's a couple other types here i wanted to talk about so we talked about string um let's get into some slightly more complex types because when you look at the built-in types that that ship with the programming language right string numbers boolean what about dates um we need to how do we work with dates or times so let's work with those here um just call me a.d though before i get to them has a question what's the difference between a decimal double and a float so i've got the documentation linked here i'm going to open it up a decimal double and a float so these all point to floating point number the numeric types it's the same article um it's a question of precision right a floating um floating number has six to nine digits to the right of the decimal place and it only takes up four bytes so not as big a deal and it's stored in a single precision type a double has 15 to 17 digits eight bytes and it's it right we start to lose precision once you get way out there it's weird but it's not quite the same right don't use float and double types in a uh in any kind of financial calculations because you're going to get some weird numbers when you get way out there towards the end that you're not quite sure about where this extra 7 appear out about 12 digits i don't know it's because it's not a precise number decimal is a bit more precise and it goes out to 28 to 29 digits it takes up 16 bytes so you're you're you're spending the memory you're allocating more space in memory to interact with your decimal types but you end up with better precision and both of them go positive negative you can go all the way to negative values all the way up to positive values hey the bald bearded builder is here so good to see you my friend so those are the difference between those all right now i wanted to talk about dates because right dates are kind of funny how what how do we do anything um with dates so let's uh come here uh yeah mark down there we go um date types right um so let's how do we work with date right so you're now into a dot net type okay so the dot net type for a date is called date time let me just yeah there we go so date time you declare a variable of type date time we'll call this um um let's call this today and right if i just want to output what's that value the date starts by default in the year one january 1st at midnight utc literally the first minute of the first day of the first year that's the default value well i don't want it to be january 1st of the year one that's weird um i want it to actually be like like august 1st 2020 right so you allocate a new date time here we're going to introduce the new keyword the new keyword says make a new one of these objects and we're going to pass in arguments to construct it so i'm going to specify the year 2020 the month august and the 1st of august when i do that now i have a date that is 20 20 august 1st okay um what if i need to specify the actual time of day right phone to specify 9 am sure ninth hour zero minutes zero seconds and now there it is now no notice it has the zulu flag here right because you can have a time zone offset indicator after it now without declaring exactly what that indicator what what time zone you're working in it's just assumed to be local time right it's it's just a date out there when you need to start working with time zones there's all kinds of interactions that you can get into and work with and we're not going to dive down into date theory but i want to show you how you can get a date to interact with um zulu is the radio character the radio call for the z um for the the z character so every now and again you'll hear me use the the radio characters for them so how's it going eagle hanson good to see you right up alpha bravo charlie you'll hear me go into those sometimes um and and sometimes i i mix up the alphabets right i'll go between radio and uh and and the faa standard ones back and forth so okay so what if i want to get the time of day out of that sure there's a time of day is it method or property i think it's a time of day property on your date that you can interact with and we reference the properties of objects by putting dot and the property name so today dot time of day and it gives me 9 am because that's what we created 9 a.m was the time of day we allocated i can also get other parts of it like the month it's the eighth month it's august right whatever you can do these interactions and the type ahead being in in some the type ahead will help you with this on your various editors in visual studio and visual studio code we have something called intellisense that you can that you can use that will automatically tell you all the various features of the variables and interactions you have there should be something like now yep intellisense here we go that's right to get the current time you better believe we got now that's a great point physitronic so if i specify just datetime.now it reports the current time so here my local time it's 10 50 on the 10th of august well what if i want to get that in utc i can put utc now and it gives me the utc time so these are the things that you can use to interact and get the time the exact time that you execute that method it's the exact time down to the second there are other ways to get interactions and get get timings down to the millisecond even the processor tick we'll talk about that another time but i can write i can once i have now right i've got those same properties because it's just another day that i can interact with like day month year hour right maybe i want something to only run during right um during the 11 o'clock hour okay if the if date time now hour is 11 do this right maybe you want to build a schedule application and you want to inspect the now hour and do something only this often go for it there you go those are the ways that you can do that do that interaction visitronic with a very good question here as we tiptoe into the topic of time zones um is there already built-in conversions for time zones like if you want to go two time zones from the current one or something like that yes yep there there are time zone objects available for you it's a little bit further down down the path on date time math that i want to get into today but you can absolutely work with time zones um and the way you reference time zones differs whether you're on windows mac or linux on windows i would refer to eastern time and i would actually reference the the text eastern time to get that time zone where if i was on a linux machine i would reference america's slash new york to get the eastern time zone so it's a little bit different depending on what what machine you're on and some of that interaction makes being able to support different machines and do that that system level interaction something that you need to um be able to handle in your code so we'll save machine and operating specific operating system specific considerations later now you're getting how everything is an object in c sharp that's right john skeet has written some amazing material on his blog about dates and times you're right you're right um now right i can display the hour but what if i what if i want to take date time let me change that back to uh today um datetime.now display the current time [Music] on current local time uh just the current local time i'll say that okay if i want to add hours right if i want to take that or some other math right if i want to take today and i want to i can add days right let's say well let's add a week to that add seven days right um no no no not that's what i wanted there we go so now i added seven days and i've got uh the tenth from the 10th oh wait a sec i got confused because they were in the wrong order display the hour for today that 9 a.m um now is the 10th and now here today add days so today was august 1st it's now august 8th when i add those days okay you're working on a project with python and dates and the upper limit is the year 3001 what's the upper limit in c sharp so just like there's a date time now there is a date time max value as well and it's the year 99 99 and december 31st and one second before midnight turning over to the year 10 000. so um add a week to the today to um august 1. okay now i can also create something called a time span and a time span is a unit of time right it's not a specific date but it's a it's a it's a way to reference and say like three hours right so we can create we can say right time span um let's call it three hours equals new right i could say new time span and i forget what the constructor is here and it's not it's not going to uh give me the intellisense to complete that i can kind of cheat because there's a time span from hours method that i can call and specify three and it'll show me three hours now now that i have three hours now i can i can add that unit of time that three hours to my date right so i can say today.add i'm not adding right i don't know exactly what three hours is right it might be coming from somewhere else but i could say today add three hours and i get the full today and it comes out to noon all right so it's a it's a unit of time it's a yeah it's a delta it's right a collection of time it's a way for you to reference some right some number of hours minutes seconds days years whatever right but you are referencing some duration effectively is what a time span is all right we've gone through a lot here we are wrapping up because we have just a few minutes left um physitronic has it has a good question here has the today object changed after add no because we didn't assign it back to today see it's still the same value if we had done um [Music] right if we had taken this uh put it here and if we had said today equals um there we go right so there it is and it's the same value because you can't see it so there's my three hours there's today add three hours and assign it back into today and there's the result so good question let me just pop that back in there get rid of that there we go i'm going to save this notebook and i'm going to head over to my console this is c-sharp with c-sharp fritz i'm going to commit these changes um [Music] clear that out and we're going to wrap up here um [Music] completed talking about uh dates and converting types uh needs some text and i need to sign my code here we go i have a yuba key that i use to sign that and i'll push out those changes and that will be available in the show repository right here and i'll get a i'll get a robot running and available here there's a link if you want to get out to the github repository but i will i will trim out the rest of this notebook with a little bit more text to describe what's going on and show some of these examples i like the suggestion of adding some links out to the official microsoft documentation and i also liked having about the first half of this scripted and and leaving the second half unscripted and answering your questions and and going through here and addressing some of the things that you want to learn about as we go through and talk about the various topics this video like all the videos in this series will be available over on the dotnet youtube channel and let's get ready to wrap things up here today that's right asaga inside internally date time and time span are represented as ticks as processor ticks and right that has a reference from the beginning of time that the processor knows about to whenever it is that you're you're indicating there all right oh thank you just call me ad appreciate the kind words really appreciate you joining us here on the visual studio channel this this video will be archived over on the youtube um and where all the code that we wrote and all of all of the questions that we had we're gonna have loaded up and and i'm gonna have out on the github repository i hope you check that out i hope you subscribe to the.net channel out on youtube um because that will be loaded up with content from here there's a link yep we'll have it we'll be doing um classes interfaces and operator methods next time but every monday morning you'll find me here talking about and getting you started with the basics of c sharp if you're interested in any complete ama everything's crazy off the hook um join me on tuesdays thursdays and sundays over on my channel c sharp fritz here on twitch and um everything goes there you can ask any question happy to answer them um and right now we're working on a blazer project building a web application with blazer
Info
Channel: dotnet
Views: 63,066
Rating: undefined out of 5
Keywords: .NET, C#, Learn C#, CSharp, csharp, c#, csharpfritz, beginner, tutorial
Id: pyN7JTQM7sU
Channel Id: undefined
Length: 114min 37sec (6877 seconds)
Published: Mon Aug 10 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.