visual c# .net programming

visual c# net tutorial and visual c# asp net web application tutorial | pdf free download
Dr.HenryEvans Profile Pic
Dr.HenryEvans,Germany,Professional
Published Date:10-07-2017
Your Website URL(Optional)
Comment
Visual C .NET Copyright: Home and Learn This Edition: December 2012 Author: Ken Carney All rights reservedIntroduction Hello, and a very warm welcome to the Home and Learn computer book for C .NET Programming (all versions, up to and including 2012). The software you need is set out below. We assume that you have absolutely no knowledge of programming. Throughout the course of this book you will learn the fundamentals of NET programming with the free edition of the Visual C .NET software. And, of course, you will start writing your own programmes. By the end of the book, you will have acquired a good understanding of what programming is all about, and have the ability to take it further, if you so wish. At the very least, you will have given your brain a good work out We hope you enjoy your computer book, and our time together. Before you make a start, though, please read the following brief sections. What you need to do the course To do this course you need the following:  A PC running the Windows XP, Vista, Windows 7, or Windows 8 operating system  The free Visual Studio Express Edition (any version up to and including 2010)  An internet connection to download the extra files mentioned in this book The Free Visual C Express Edition This book uses the free edition of Visual Studio. At the time of writing, you can download it from here: http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products If you have Windows 7 or 8 then you can get the version for Express Products 2012, Express for Windows Desktop. If you don't have Windows 7 or 8 then you may have problems installing version 2012. In which case, click the link for 2010 Express products. Whichever version you get, though, our course will cover it. We cannot, however, accept questions about the installation of the Microsoft software. Additional Files Throughout this book, you will see references to additional files. These can now be downloaded from our web site. Connect to the internet and go to the following web page: www.homeandlearn.co.uk/downloads/downloads.html Once on the page, click the link for your course book, and save the Zip file to your own hard drive. If you have any problems downloading the files, please contact us at the following email address: enquiryhomeandlearn.co.uk You can now make a start. Good luck with your programming Getting Started Home and Learn Getting Started with C Open the Visual C Express software from your programs menu. When you first open C (pronounced C Sharp), you should see a screen something like this in Visual C 2008: If you have the 2010 version of Visual C Express then your screen looks like this on the next page: – 9 – Getting Started Home and Learn The Visual Studio 2012 opening screen will look like this: When you're looking at this piece of software for the first time, it can seem hugely complex and daunting. The temptation is to think you're never going to get to grips with something so difficult. But don't worry - after a few lessons things will start to feel familiar, and you won't feel nearly half as intimidated as you do now – 10 – Getting Started Home and Learn What we’re going to do first is to create a very simple programme, so that you can see what makes up a C project. By the end of this chapter, you’ll have learned the following: • How to create new projects • What the Solution Explorer is • The various files that make up of a C project • How to save your work • How to run programmes • The importance of the Main statement The simple programme we’ll create is called a Console Application. We won’t be doing much else with this type of application, as this is a book about Windows Forms Applications. Off we go then A Simple C Console Application A Console Application is one that looks like a DOS window. If you don’t know what these are, click your Start menu in the bottom left of your screen. In Windows XP, click on Run. From the dialogue box that appears, type cmd: In Vista and Windows 7, type cmd in the search box at the bottom of the start menu. In Windows 8, the search box is on the Start Screen page. You’ll then see the search results appear: – 11 – Getting Started Home and Learn Click cmd.exe to see the console appear. Click OK and you’ll see a black screen, like this one: This is the type of window you’ll see for our Console Application. When you create your Window forms, there's a whole lot of code to get used to. But Console Applications start off fairly simple, and you can see which part of the programme is the most important. – 12 – Getting Started Home and Learn So with Visual C Express open, click File from the menu bar at the top. From the File menu, select New Project (or click the New Project link on the left of the opening screen in versions 2010 and 2012): When you click on New Project, you’ll see the following dialogue box appear in version 2008: Or this one in version 2010 of the software: – 13 – Getting Started Home and Learn For 2012 users, click on Templates from the list on the left. Under Templates, click on Visual C. You'll then see Console Application appear in the middle: For all versions, the New Project dialogue box is where you select the type of project you want to create. If you only have the Express edition of Visual C, the options are limited. For the rest of this book, we’ll be creating Windows Applications. For now, select Console Application. Then click OK. When you click OK, a new Console Application project will be created for you. Some code should be displayed (older versions will have fewer using statements at the top): – 14 – Getting Started Home and Learn As well as the code, have a look on the right hand side and you’ll see the Solution Explorer. This is where all the files for your project are. The code itself will look very complicated, if you’re new to programming. We’ll get to it shortly. For now, right click the Program.cs tab at the top, and click Close from the menu that appears: Or just click the X in C 2010 and 2012 : Now double click the Program.cs file in the Solution Explorer: – 15 – Getting Started Home and Learn When you double click Program.cs, you should see the code reappear. So this code is the programme that will run when anyone starts your application. Now click the plus symbol (arrow symbol in version 2012) next to Properties in the Solution Explorer above. You’ll see the following: The file called AssemblyInfo.cs contains information about your programme. Double click this file to open it up and see the code. Here’s just some of it: The reddish colour text is something you can change. You can add a Title, Description, Copyright, Trademark, etc. But right click the AssemblyInfo.cs tab at the top, and click Close from the menu. Now, in the Solution Explorer, click the plus symbol next to References: – 16 – Getting Started Home and Learn These are references to code built in to C (you won’t see as many entries in earlier versions of the software). Much later, you’ll see how to add your own files to this section. Before we add some code, let’s save the project. Saving your work When you save your work, C will create quite a few folders and files for you. Click File from the menu bar at the top, then Save All: – 17 – Getting Started Home and Learn When you click Save All, you’ll see the following dialogue box appear in versions 2008 and 2010: (2012 users won't need to do anything here, as this above information was displayed when you created a new project earlier.) You can type any name you like for your project. The default Name is ConsoleApplication1. Have a look at the location of the project, though: C:\Users\Owner\documents\visual studio 2010\Projects In XP, however, you’ll see something like this: C:\Documents and Settings\kayspc\My Documents\Visual Studio 2010\Projects So it’s going to be saved to the “documents” folder of this computer. In the “documents” folder you’ll find another one called Visual Studio, followed by a year. In this folder there will be one called Projects. Before clicking the Save button, make sure there is a tick in the box for “Create directory for solution”. Then click Save. Now open up Windows Explorer (Hold down the Windows key on your keyboard, then press the letter “e”). Navigate to the folder location above. In the image below, we’ve used Windows Explorer to navigate to the Visual Studio 2010 folder: – 18 – Getting Started Home and Learn Double click the Projects folder to see inside of it. You should see a folder called ConsoleApplication1. Double click this folder and you’ll see the following: So there’s another folder called ConsoleApplication1. There are also two files: one that ends in sln, and one that ends in suo. The sln file is the entire solution. Have a look at the Solution Explorer again: The one highlighted in blue at the top refers to the sln file. The suo file contains information about the Visual Studio environment – whether the plus symbols are expanded in the Solution Explorer, what other files you have open in this project, and a whole host of other settings. (If you can’t see the suo file click Tools Folder Option in Windows Explorer. In Vista and Windows 7/8, you may have to click Organise Layout Menu Bar first. Click the View tab, and select the option for “Show hidden files and folders”.) Double click your ConsoleApplication1 folder, though, to see inside of it: – 19 – Getting Started Home and Learn Now we have three more folders and three files (two files in earlier versions of c). You can see the bin and obj folders in the Solution Explorer: Click ConsoleApplication1, second from the top. Then click the icon for Show all Files, circled in red in the image above. To see All Files in version 2012, click the symbol circled in the image below: The bin and obj folders will appear. Click the plus symbol or arrows to see what’s inside of these folders: – 20 – Getting Started Home and Learn The important one for us is the Debug folder under bin (there’ll be an extra file ending in .manifest in c 2010). You’ll see why it’s important in a moment. However, it’s time to write some code Your first line of code The only thing we’ll do with the code is to write some text to the screen. But here’s the code that Visual C prepares for you when you first create a Console Application: – 21 – Getting Started Home and Learn For now, ignore the lines that start with using as we’ll get to them later in the book. (The image above is from version 2012 - earlier versions will have fewer using lines). But they add references to in-built code. The namespace line includes the name of your application. A namespace is a way to group related code together. Again, don’t worry about the term namespace, as you’ll learn about this later. The thing that’s important above is the word class. All your code will be written in classes. This one is called Program (you can call them anything you like, as long as C hasn’t taken the word for itself). But think of a class as a segment of code that you give a name to. Inside of the class called Program there is this code: static void Main(string args) This piece of code is something called a Method. The name of the Method above is Main. When you run your programme, C looks for a Method called Main. It uses the Main Method as the starting point for your programmes. It then executes any code between those two curly brackets. The blue words above are all special words – keywords. You’ll learn more about them in later chapters. But position your cursor after the first curly bracket, and then hit the enter key on your keyboard: The cursor automatically indents for you, ready to type something. Note where the curly brackets are, though, in the code above. You have a pair for class Program, and a pair for the Main method. Miss one out and you’ll get error messages. The single line of code we’ll write is this (but don’t write it yet): Console.WriteLine("Hello C Sharp"); First, type the letter “C”. You’ll see a popup menu. This popup menu is called the IntelliSense menu. It tries to guess what you want, and allows you to quickly add the item from the list. But it should look like this, after you have typed the letters “Con” (the list will be styled differently, depending on your version of the C software): – 22 – Getting Started Home and Learn The icon to the left of the word Console on the list above means that it is a Class. But press the Enter key on your keyboard (you can also press the tab key). The word will be added to your code Now type a full stop (period) immediately after the word Console. The IntelliSense menu appears again: You can use the arrow keys on your keyboard to move up or down the list. But if you type Write and then the letter “L” of Line, IntelliSense will automatically move down and select it for you: – 23 – Getting Started Home and Learn Press the enter or tab key to add the word WriteLine to your code: Now type a left round bracket. As soon as you type the round bracket, you’ll see something like this: WriteLine is another Method (a Method is just some code that does a particular job). But the box is telling you that there are 19 different versions of this Method. You could click the small arrows to move up and down the list. Instead, type the following: “Hello C Sharp” Don’t forget the double quotes at the start and end (and don't copy and paste the line above as you'll have the wrong type of double quotes for C). These tell C that you want text. Your code will look like this: Now type a right round bracket: – 24 – Getting Started Home and Learn Notice the red wiggly line at the end. This is the coding environment’s way of telling you that you’ve missed something out. The thing we’ve missed out is a semicolon. All complete lines of code in C must end with a semicolon. Miss one out and you’ll get error messages. Type the semicolon at the end and the red wiggly line will go away. Your code should now look like this: Note all the different colours in your code. Visual C colours the different parts of your code. The reddish colour between double quotes means that you want text; the green colour means it’s a Class; blue words are ones that C reserves for itself. These are called Keywords. (If you want, you can change these colours. From the menu bar at the top, click Tools Options. Under Environment, click Fonts and Colors.) Time now to Build and Run your code Running your Programmes You can test your programme a number of ways. First, it has to be built. This is when everything is checked to see if there are any errors. Try this: • From the View menu at the top of Visual Studio Express, click Output. You’ll see a window appear at the bottom (In C 2010, if you can’t see an Output entry, click the Tools menu. From the Tools menu, select Settings Expert Settings. The Output menu item should then appear on the View menu.) – 25 –

Advise: Why You Wasting Money in Costly SEO Tools, Use World's Best Free SEO Tool Ubersuggest.