C# vs .NET

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome along or welcome back to our channel my name is chris roberts and this is robert's dev talk now a few months ago i made a video all about some of the really cool things that you can make with c sharp in our video i talked about making games with unity machine learning models with ml.net iot projects and so on now i've recently gone back and watched that video and i noticed i made a bit of a mistake and that is because i referred to c sharp and net interchangeably as if they were the same thing and that's not technically correct because even though they are very closely related technologies they are two different things entirely so in this video i'm going to explain to you the difference between net and c sharp what they both do how they differ and how they work so well together so if you've ever been curious about that subject then stay tuned let's go so first of all let's start with c sharp c is essentially a computer programming language it's a set of syntax and keyword rules that you can use to make a computer do your bidding by controlling operations on its cpu and memory now c-sharp shares a lot of features with other languages such as typescript or c plus or php in that it contains some building blocks for writing computer programs among these building blocks are variables which allow you to store such things as strings for names and addresses and so on numbers which can be integers or floating point numbers with decimal places and booleans and these store true or false values for example to store the result of a yes or no question you can also use loops to repeat a certain piece of code either a set number of times or as long as a certain condition is true you can use logic to control the flow of your application using for example if and else blocks so you can say if something is true then run this piece of code otherwise do something else and you can also use functions to wrap up a piece of code that you can run from anywhere in your application without having to repeat that code over and over again functions are also useful because you can pass in information modify the information and then return the updated information to the code that calls it now this is just scratching the surface of the features that are available within c-sharp there are many many other things you can do but these are the fundamental building blocks that will get you started writing your first program so now let's take a look at an example of a very simple but perfectly valid program written in c sharp so let's create a simple c sharp program that takes a starting balance and then calculates compound interest on that balance for a period of five years so first of all let's create a variable to hold our balance this will be of type double which is a number with decimal places we'll set that value to 1000. next we'll create another variable this time of type integer which is just a whole number that will hold the starting year that we want to base our calculations on and we'll set it to 2020. next for each year after our start year we want to take the balance and multiply it by the interest rate and store it back in our balance value so we'll do this using a loop this is a for loop we'll set a counter and call it i and set that to equal one the loop will run while that counter is below six and each time the loop runs the counter will be incremented by one inside the loop we'll create a new value to store the current year in the loop and we'll set that to the start year plus the counter value we'll take our balance multiply it by a 1.1 or an interest rate of 10 and store it back over the original balance value now let's create a new variable once again this time of type string this will store a message that we can show to our user now this program is perfectly valid c sharp it will run fine it won't cause any errors however it also won't do anything it won't interact with the user in any way so this is where dot net comes in so what is dot net well previously we mentioned functions that are a feature in c sharp that can wrap up pieces of code and they can be run from anywhere and net contains thousands and thousands of functions that allow c-sharp to perform useful operations such as sending information over a network writing things to file interacting with the user and so on and these are the kind of things that a useful computer program will need to do so let's take a look back at our example program and update it to do something useful using the library of functions available in net now one of the most simple programs that you can create with net and c-sharp is a console application this interacts with the user through the console or command line whether that's on windows mac or linux so first of all let's enhance our application by adding a new line after we create our message and that will be console writeline and then we'll print out our message now if we run this application we can see straight away that it's a lot more useful as it shows the user what it's doing on each run of our loop however notice that our program is still quite limited because we set our starting balance to 1000 this cannot be changed by the user and we're also setting the start year to 2020. what would be really useful is if the user could set the balance and the start year was set from the current year on the calendar and we can easily achieve these things using the tools built into the.net code library so first of all at the start of our application let's print out a message to the user prompting them to enter a starting balance next we'll replace the hard-coded balance with a function that converts string values to numbers and we want to read the user's input from the console so we'll pass into this function the console read line and what we're doing here with dot net is we're taking the input set by the user and converting it to a number that will store in our balance next we can change the start year to use the current year on the calendar using the date time tools built into net so we'll replace start year with date time now and the year component of the date this time we run our program it becomes a lot more useful because it prompts for a starting balance we also see that the year starts at 2023 this is because net has taken the current year and incremented it each time the loop runs and notice we can run this program as many times as we like each time with a different input and the program will respond appropriately now dot net is not just a library of functions or a code library available to c sharp it also has quite a number of other features as well like many other languages such as c plus plus or java the code that you write in c sharp is not the final version or run on the device it needs to be interpreted as something that your machine can understand and that is where the net build process comes in this takes your c-sharp code and converts into something called il or intermediate language this is a language that is ready to be run on the device of your choice and then another part of net called the clr or common language runtime takes that code and converts it into the complex machine instructions that your device and cpu can't understand now this might sound like a convoluted process however it actually happens really fast and it enables some really cool features such as memory optimization on the fly and it also allows your code to be optimized specifically for the device and machine that is running on one other benefit of the clr or common language runtime is that it means other languages apart from c-sharp can use the.net library and the tools available for example you can use f-sharp which is another language by microsoft or visual basic all in all net and c-sharp are a very powerful platform for building applications around any kind of device you can run.net of course on windows you can run it on a mac you can run.net applications on an ipad even on tvs and linux devices it's an incredibly flexible powerful technology set that i am really excited about and it's only getting better and better and faster and faster so if you'd like to see more videos about.net and c-sharp and some of the cool things you can build check out the playlist link down below if you've enjoyed this video and if you found it useful then please do drop us a like and if you like this kind of content then please do subscribe as well and hit that notification icon so you never miss out on one of our videos thank you so much for watching happy coding see you next time [Music] you
Info
Channel: Roberts Dev Talk
Views: 28,799
Rating: undefined out of 5
Keywords: c#, c sharp, .net, .net core, coding tutorial, what is .net, what is c#, software development, learning to code, .net framework, .net 5, .net 6, code, coding, tutorials, developer
Id: exBvpiVcmGo
Channel Id: undefined
Length: 8min 27sec (507 seconds)
Published: Mon Jan 17 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.