In this program we are going to have a quick tour of Visual Studio and build a very simple C sharp application so here I've got Visual Studio open to file new project okay in this dialogue on the left a section called templates and here you see the kind of applications we can build with c-sharp so as you seen the least we can build desktop applications web applications apps for cloud mobile services workflows and various kind of things but in this course and the subsequent parts of this course we're just going to focus on console applications a console application is a very simple application that does not have a graphical user interface and it's a great learning tool for learning a new language so we're not going to be distracted by various complexities of larger applications so on the left side select windows and on the right side select console application then give a name to your project so let's call it hello world which is a common tradition when learning a new language and specify a location you can put it wherever you want I know this concept of solution Visual Studio we have this concept of solution which can have one or more projects with a very simple application you have only one solution and one project but as your application grows you add more projects each responsible for something different but now we don't have to worry about it now click OK alright let's see what's happening here some developers get a little bit intimidated the first time they open visual studio and that's fair enough because there are so many menus and panels here that is a bit confusing but let me tell you something 90% of the time you're gonna use only 10% of these or even less so don't worry about all these menus here you don't need to use all of them at all times 90% of the time all you need is the code editor here you need the solution Explorer in fact I personally pardonne ever used solution Explorer because I do everything with my keyboard and if you watch my course double your coding speed you will see that everything is possible with keyboard so you don't need these panels here you don't need to grab your mouse and navigate around you don't really need this stuff also none of the stuff on the toolbar are ever required don't worry about it everything you can do with your keyboard alright now let's take a look at this first t-shirt program so we created a console application and on the right side you see the solution Explorer panel in case you don't see that go to view and select solution Explorer top you see we have a solution which has only one project under that we've got the project called hello world look at these four items here properties expand that we have a file here called assembly info this is the identification or the assembly that will be produced as a result of compiling this application so when we compile the console application we're going to get an executable and that's an assembly that assembly has an identification look at these attributes here like the title description which is currently not set company product copyright trademark culture AG weight you know various kind of things like even version so these are all part of assembly identification or assembly manifest in most cases you don't have to worry about it but if you want to create an assembly and you want to distribute it send to other people then you may want to come here and give you the proper name and a proper version so for now we don't have to worry about it under references you see any assemblies that this project is referencing to do its job you create a project with Visual Studio by default it as a reference to a bunch of assemblies that you'll see here these are all part of dotnet framework so at a minimum Visual Studio assumes you're gonna use classes in system assembly or system the data to work with databases and so on you may not necessarily use all these assemblies in your project but that's just part of the template aptoide config is an XML where we store the configuration for this application sometimes you may want to store connection strings to the database or you may want to have some settings about your application all of them will end up here and finally you see programmed of CS which is where we're gonna start writing code all right let's see what's happening here so in this file program the CS on the top you see a bunch of using statements what is this all about well our project is called a hello world so by default Visual Studio creates a namespace called hello world when we write code in this namespace we have access to any classes defined in this namespace so if you want to use a class that is defined in a different namespace we need to import it in our code file and that's why we use the using statement so by default Visual Studio as these five using statements system is a namespace in dotnet framework and that's where we have all these basic utility classes and primitive types there system that collections that generic is used to work with lists collections and so on system that link is used to work with data and is a comprehensive topic that I have covered in my c-sharp advanced course system the text is used to work with tags and coding and stuff like that and finally system the threading is used to build multi-threaded applications in this video we're going to create a very simple application and we're not going to use any of these four namespaces here so we're just gonna use system for now I'll leave them there and then I will show you how to clean them up all right so here's our namespace and insight namespace by default we have a class called program so every console application you create with Visual Studio has a class called program inside program by default we have a method or a function called main and that's the entry point to the application so when you run your application CLR execute the code inside main method and that's where everything kicks off this method is declared as static and something I'm going to cover later in the next section methods have input and output so what goes inside paranthesis is the input to the method which we call parameter or argument note that parameters are optional but in this case in the default template the main method has a parameter called args which is of type string array we're going to learn about string array in the next section what you see before the method name is the return type or the output of the method void in c-sharp means nothing that means this method does not return any value it just contains some code that's it also note that C sharp is a case sensitive language so this main has to be with capital M otherwise CLR is not going to find this method as the entry point of the application okay and one last thing is not these curly braces so very rare we have a block of code we need to surround it with curly braces so that is applicable for methods for classes and for namespaces alright now let's write a very simple seizure program so let's go here we have a class called console which is used to read data from console or write data to it it has a bunch of methods and access this method using the dot notation and here you see various members of this class methods are indicated by a purple cube so beep is used to play a beep sound or clear is used to clear the console we're going to use the right line method this method can optionally take a parameter I'm gonna pass a string here hello world just that I note that statements in c-sharp terminate with a semicolon as you see here take a look at using system on the top do you see that it's highlighted whereas the others are grayed out the reason for that is in this file we are using a class called console which is defined in the system namespace that's why that using statement is active we are not using any classes defined in other namespaces and that's why they're grayed out so we can get rid of them to make our code cleaner we can either delete each one by ctrl X like that or if you're using resharper you can get rid of all of them by pressing Alt + Enter here and selecting the first option which is remove unused directives in file so it's faster now let's run the application with ctrl + f5 so this window that you see here this black window is what we call console and that's why this kind of project is called console application you okay that's it for this lecture from this point in every lecture we're going to learn something new about c-sharp and we can write more interesting and more complex programs I hope you enjoyed this lecture and thank you 

Post a Comment

If you have any doubt please let me know

Previous Post Next Post