Visual studio and c# Tutorial

Introduction to Visual Studio and C# | pdf free download
Dr.JamesSmith Profile Pic
Dr.JamesSmith,France,Professional
Published Date:11-07-2017
Your Website URL(Optional)
Comment
University College of Southeast Norway Introduction to Visual Studio and C HANS-PETTER HALVORSEN, 2016.09.26 http://home.hit.no/hansha Table of Contents 1. Introduction ...................................................................................................................... 5 1.1. Visual Studio ............................................................................................................... 5 1.2. C ................................................................................................................................ 6 1.3. .NET Framework ......................................................................................................... 6 1.4. Object-Oriented Programming (OOP) ........................................................................ 7 2. Visual Studio ...................................................................................................................... 8 2.1. Introduction ................................................................................................................ 8 2.2. Getting Started ........................................................................................................... 8 2.2.1. Integrated Development Environment (IDE) ....................................................... 8 2.2.2. New Project ......................................................................................................... 9 2.2.3. Solution Explorer ............................................................................................... 10 2.2.4. Toolbox .............................................................................................................. 11 2.2.5. Editors and Designers ........................................................................................ 12 2.2.6. Properties window ............................................................................................ 12 2.2.7. Build and Debug Tools ....................................................................................... 13 3. Windows Programming ................................................................................................... 15 3.1. Introduction .............................................................................................................. 15 3.1.1. Windows Forms ................................................................................................. 15 3.1.2. WPF ................................................................................................................... 16 3.2. Hello World ............................................................................................................... 16 4. Getting Started with C ................................................................................................... 19 2 3 Table of Contents 4.1. Introduction .............................................................................................................. 19 4.2. Data Types and Variables .......................................................................................... 19 4.2.1. Boolean type ..................................................................................................... 20 4.2.2. Numeric types: Integrals, Floating Point, Decimal ............................................ 20 4.2.3. String type ......................................................................................................... 20 4.2.4. Arrays ................................................................................................................ 21 4.3. Control Flow ............................................................................................................. 21 4.3.1. The if Statement ................................................................................................ 21 4.3.2. The switch Statement ........................................................................................ 22 4.4. Loops ......................................................................................................................... 23 4.4.1. The while Loop .................................................................................................. 23 4.4.2. The do Loop ....................................................................................................... 23 4.4.3. The for Loop ...................................................................................................... 24 4.4.4. The foreach Loop ............................................................................................... 24 4.5. Methods ................................................................................................................... 24 4.5.1. Nonstatic Methods ............................................................................................ 25 4.5.2. Static Methods .................................................................................................. 25 4.6. Namespaces .............................................................................................................. 26 4.7. Classes ...................................................................................................................... 26 4.7.1. Constructor ........................................................................................................ 27 4.8. Properties ................................................................................................................. 29 4.9. Naming Convention .................................................................................................. 31 5. More Object-oriented Techniques .................................................................................. 33 5.1. Inheritance ................................................................................................................ 33 5.2. Polymorphism ........................................................................................................... 34 5.3. Encapsulation ........................................................................................................... 35 Tutorial: Introduction to Visual Studio and C 4 Table of Contents 6. Exception Handling .......................................................................................................... 36 7. Windows Forms Example ................................................................................................ 38 8. Web Programming .......................................................................................................... 44 8.1. Introduction .............................................................................................................. 44 8.2. HTML ......................................................................................................................... 44 8.3. Web Browser ............................................................................................................ 44 8.4. CSS ............................................................................................................................ 45 8.5. JavaScript .................................................................................................................. 45 8.6. ASP.NET .................................................................................................................... 45 8.7. AJAX/ ASP.NET AJAX ................................................................................................. 46 8.8. Silverlight .................................................................................................................. 46 9. Database Programming ................................................................................................... 47 9.1. ADO.NET ................................................................................................................... 47 Tutorial: Introduction to Visual Studio and C 1. Introduction In this Tutorial we will use Visual Studio and C. C is the programming language, while Visual Studio is the development environment. Useful links: Visual Studio: http://msdn.microsoft.com/en-us/library/dd831853.aspx C: http://msdn.microsoft.com/en-us/library/kx37x362.aspx 1.1. Visual Studio Microsoft Visual Studio is an integrated development environment (IDE) from Microsoft. It can be used to develop console and graphical user interface applications along with Windows Forms applications, web sites, web applications, and web services in both native code together with managed code for all platforms supported by Microsoft Windows, Windows Phone, Windows CE, .NET Framework, .NET Compact Framework and Microsoft Silverlight. Below we see the integrated development environment (IDE) in Visual Studio: 5 6 Introduction New projects are created from the “New Project” window: 1.2. C C is pronounced “see sharp”. C is an object-oriented programming language and part of the .NET family from Microsoft. C is very similar to C++ and Java. C is developed by Microsoft and works only on the Windows platform. 1.3. .NET Framework The .NET Framework (pronounced “dot net”) is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allow language interoperability (each language can use code written in other languages). The .NET library is available to all the programming languages that .NET supports. Programs written for the .NET Framework execute in a software environment, known as the Common Language Runtime (CLR), an application virtual machine that provides important services such as security, memory management, and exception handling. The class library and the CLR together constitute the .NET Framework. Tutorial: Introduction to Visual Studio and C 7 Introduction 1.4. Object-Oriented Programming (OOP) Object-oriented programming (OOP) is a programming language model organized around "objects" rather than "actions" and data rather than logic. Historically, a program has been viewed as a logical procedure that takes input data, processes it, and produces output data. The first step in OOP is to identify all the objects you want to manipulate and how they relate to each other, an exercise often known as data modeling. Once you've identified an object, you generalize it as a class of objects and define the kind of data it contains and any logic sequences that can manipulate it. Each distinct logic sequence is known as a method. A real instance of a class is called an “object” or an “instance of a class”. The object or class instance is what you run in the computer. Its methods provide computer instructions and the class object characteristics provide relevant data. You communicate with objects - and they communicate with each other. Important features with OOP are: • Classes and Objects • Inheritance • Polymorphism • Encapsulation Simula was the first object-oriented programming language. Simula was developed in the 1960s by Kristen Nygaard from Norway. Java, Python, C++, Visual Basic .NET and C are popular OOP languages today. Since Simula-type objects are reimplemented in C++, Java and C the influence of Simula is often understated. The creator of C++ (1979), Bjarne Stroustrup (from Denmark), has acknowledged that Simula was the greatest influence on him to develop C++. Tutorial: Introduction to Visual Studio and C 2. Visual Studio 2.1. Introduction Home page of Visual Studio: http://www.microsoft.com/visualstudio There exist different versions of Visual Studio, such as Visual Studio Express (free), Visual Studio Professional, Visual Studio Premium and Visual Studio Ultimate. 2.2. Getting Started 2.2.1. Integrated Development Environment (IDE) The Visual Studio product family shares a single integrated development environment (IDE) that is composed of several elements: the Menu bar, Standard toolbar, various tool windows docked or auto-hidden on the left, bottom, and right sides, as well as the editor space. The tool windows, menus, and toolbars available depend on the type of project or file you are working in. Below we see the Visual Studio IDE (Integrated Development Environment): 8 9 Visual Studio 2.2.2. New Project The first thing you do when you want to create a new application is to create a new project. This can be done from the Start Page: Or from the File menu: Then the “New Project” window appears: Tutorial: Introduction to Visual Studio and C 10 Visual Studio In this window you will select an appropriate template based on what kind of application you want to create, and a name and location for your project and solution. The most common applications are: • Windows Form Application • Console Application • WPF Application • ASP.NET Web Application • Silverlight Application 2.2.3. Solution Explorer Solutions and projects contain items that represent the references, data connections, folders, and files that you need to create your application. A solution container can contain multiple projects and a project container typically contains multiple items. Tutorial: Introduction to Visual Studio and C 11 Visual Studio 2.2.4. Toolbox The Toolbox contains all the necessary controls, etc. you need to create your user interface. See Figure below. The Toolbox contains all the controls, etc. we can use in our user interface. In order to use them in our user interface, we just drag and drop them to the “Form”, as shown below: Tutorial: Introduction to Visual Studio and C 12 Visual Studio 2.2.5. Editors and Designers Visual Studio has different editors and design tools. Graphical User Interface Designer: Code Editor: 2.2.6. Properties window Each control we have on our user interface has lots of Properties we can set. Tutorial: Introduction to Visual Studio and C 13 Visual Studio This is done in the Properties window: 2.2.7. Build and Debug Tools In Visual Studio we have lots of Build and Debugging Tools. Build menu: Below we see the Build menu: The most used tool is “Build Solution” (Shortcut Key: F6). Debug menu: Below we see the Debug menu: Tutorial: Introduction to Visual Studio and C 14 Visual Studio The most used tool is “Start Debugging” (Shortcut Key: F5). Tutorial: Introduction to Visual Studio and C 3. Windows Programming 3.1. Introduction When creating ordinary Windows applications, we can select between the following: • Windows Forms Application • WPF Applications (Windows Presentation Foundation) Windows Forms is the standard way of creating Windows applications and has existed in many years, even before .NET 1.0 (2002) was introduced. WPF is a new approach from creating Windows applications and was introduced with .NET Framework 3.0 (2006). For example has the Visual Studio IDE been entirely rewritten using WPF. Windows Forms Application and WPF Applications will be explained in more detail below. 3.1.1. Windows Forms Windows Forms is the standard way of creating Windows applications. Select “Windows Forms Application” in the “New Project” window: 15 16 Windows Programming 3.1.2. WPF Developed by Microsoft, the Windows Presentation Foundation (or WPF) is a computer- software graphical subsystem for rendering user interfaces in Windows-based applications. WPF is intended to take over for the traditional Windows Forms. The graphical user interface in WPF is designed using XAML (Extensible Application Markup Language). XAML: Following the success of markup languages for web development, WPF introduces a new language known as eXtensible Application Markup Language (XAML), which is based on XML. XAML is designed as a more efficient method of developing application user interfaces Select “WPF Application” in the “New Project” window: 3.2. Hello World We start by creating a traditional “Hello World” application using Windows Forms. The application is shown below: Tutorial: Introduction to Visual Studio and C 17 Windows Programming The Visual Studio IDE looks like this: In this project we use a simple TextBox (textBox1) and when we start the program the text “Hello World” is written to the TextBox. The code is as follows: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 public partial class Form1 : Form public Form1() InitializeComponent(); Tutorial: Introduction to Visual Studio and C 18 Windows Programming private void Form1_Load(object sender, EventArgs e) textBox1.Text = "Hello World"; Tutorial: Introduction to Visual Studio and C 4. Getting Started with C C is a modern Object-oriented programming language. Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction, encapsulation, messaging, modularity, polymorphism, and inheritance. 4.1. Introduction In this chapter we will start with the basic all programming languages have:… • Data Types and Variables • Control Flow: If-Else, etc. • Loops: While Loops, For Loops, etc. Further we will introduce the following: • Namespaces • Classes • Data Fields • Methods • Properties In the next chapter we will go more in depth of what Object-oriented programming is and introduce the following important OOP topics: • Inheritance • Polymorphism • Encapsulation Note C is case-sensitive. 4.2. Data Types and Variables 19 20 Getting Started with C “Variables” are simply storage locations for data. You can place data into them and retrieve their contents as part of a C expression. The interpretation of the data in a variable is controlled through “Types”. The C simple types consist of: • Boolean type • Numeric types: Integrals, Floating Point, Decimal • String type 4.2.1. Boolean type Boolean types are declared using the keyword “bool”. They have two values: “true” or “false”. In other languages, such as C and C++, boolean conditions can be satisfied where 0 means false and anything else means true. However, in C the only values that satisfy a boolean condition is true and false, which are official keywords. Example: bool content = true; bool noContent = false; 4.2.2. Numeric types: Integrals, Floating Point, Decimal Example: int i=35; long y=654654; float x; double y; decimal z; 4.2.3. String type Example: string myString=”Hei på deg”; Special characters that may be used in strings: Tutorial: Introduction to Visual Studio and C

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