Penn P. Wu, Phd. 1 Lecture #1 Introducing Visual C# Introduction

Total Page:16

File Type:pdf, Size:1020Kb

Penn P. Wu, Phd. 1 Lecture #1 Introducing Visual C# Introduction Lecture #1 Introducing Visual C# Introduction to According to Microsoft, C# (pronounced “C sharp”) is a programming language that is the C# designed for building a variety of applications that run on the .NET Framework. C# is simple, Language and powerful, type-safe, and object-oriented. It provides many innovations to enable rapid the .NET application development while retaining the expressiveness and elegance of C-style languages. Framework C# was developed around 2000 by Microsoft within its .NET initiative and later approved as a standard by Ecma and ISO. Microsoft’s Visual Studio supports Visual C# with a full-featured code editor, compiler, project templates, designers, code wizards, a powerful and easy-to-use debugger, and other tools. C# programs run on the .NET Framework, which is an integral component of Windows that includes a virtual execution system called the common language runtime (CLR) and a unified set of class libraries. The CLR is Microsoft’s implementation of the common language infrastructure (CLI). It is an international standard that is the basis for creating execution and development environments in which languages and libraries work together seamlessly. Visual Studio Visual Studio 2017 is a rich, integrated development environment (IDE) for creating stunning 2017 and the applications for Windows, Android, and iOS, as well as modern web applications and cloud Developer services. It is a full-featured and extensible toolkit for developers to build Windows-based Command applications. As of January 2019, Microsoft says “Visual Studio Community is free for Prompt individual developers, open source projects, academic research, training, education, and small professional teams”. Students can, thus, download it from the https://www.visualstudio.com/downloads/ website. The Developer Command Prompt for Visual Studio automatically sets the environment variables that enable developers to easily use the .NET Framework tools to hand-code applications. The Developer Command Prompt is installed with full or community editions of Visual Studio, although it is not installed with the Express versions of Visual Studio. Throughout this class, students will learn to hand-code C# programs and compile them with Visual Studio’s Developer Command Prompt. Later lectures will discuss about the C# programming basics in more detail. Creating C# C# programmers write text-based source codes similar to the following example using any text source files editor such as the Microsoft Notepad, and then compile the source codes to object codes with C# compiler. The term “text-based” means the content consists of only a combination of English characters (alphabet, numerals, and symbols). namespace Samples { class Welcome { static void Main(string[] args) { System.Console.Write("Welcome to CIS218 Visual C#!"); } } } A “compiler” is a special program that reads statements written in the C# programming language and converts the “text-based” content into the binary “machine code” for the computer’s processor to read and execute. During compilation the compiler transforms source code into pieces of “object codes”. Each piece of object codes cannot be executed. The Visual C# - Penn P. Wu, PhD. 1 compiler must further assemble object codes into one single executable application with the .exe extension in order to be executable in the Windows environment. The Windows operating systems will execute the completed .exe applications. By the way, each object code is known as an “assembly” in the .Net platform. The following figure illustrates how the C# compiler converts a C# source code into an .exe application. Object code 1 class Welcome 10011001100111 { Object code 2 10001111001111 00000011110010 } 000111110011 Object code n C# source codes must be saved as text file and adopt the “.cs” file extension, such as “Welcome.cs”. Throughout this course, the instructor recommends students to use Microsoft Notepad as editor to write all the source codes. The following figure illustrates how to use Notepad to save the source code in a file named “Welcom.cs”, which will be saved as a generic text file. In a Notepad window, click File and then “Save As...” can lead to the following figure. Always make sure to the “Save as type:” is changed to “All Files (*.*); otherwise, Notepad might automatically add “.txt” to the file name (“Welcome.cs.txt”). Another way to use Notepad to create a source file named “Welcome.cs” is by typing notepad.exe Welcome.cs (or notepad Welcome.cs) and pressing [Enter] in the Developer Command Prompt. C:\Program Files\Microsoft Visual Studio\2017\Community>notepad.exe Welcome.cs In this course, the instructor recommends students to create a “C:\cis218” directory and save all the Visual C# source codes in that directory. The Developer Command Prompt supports the MS-DOS commands, such as “md” and “cd”. The “md” command can create a new directory, while the “cd” command can change from current directory to the specified directory. To create a new directory named “cis218” under the “root” directory of the “C” drive, type md c:\cis218 and press [Enter]. C:\Program Files\Microsoft Visual Studio\2017\Community>md C:\cis218 To change to that directory, type cd c:\cis218 and press [Enter]. C:\Program Files\Microsoft Visual Studio\2017\Community>cd C:\cis218 C:\cis218> Throughout this course, students should learn to create a source file in the Developer Command Prompt by typing notepad.exe Welcome.cs (or simply notepad Welcome.cs) and press [Enter] in the prompt. Click “Yes” after. C:\cis218>notepad Welcome.cs In a Windows machine with Visual Studio installed successfully, programmers can invoke the C# compiler by typing its name, csc.exe, followed by options and the file name of source code Visual C# - Penn P. Wu, PhD. 2 on the Developer Command Prompt. The following demonstrates how to compile the source code “Welcome.cs” to a self-executable program “Welcome.exe” by typing csc.exe Welcome.cs (or simply csc Welcome.cs) and press [Enter]. C:\cis218>csc Welcome.cs Microsoft (R) Visual C# Compiler version 1.0.0.50618 Copyright (C) Microsoft Corporation. All rights reserved. During the compilation, the compiler creates a new file, Welcome.exe, which is a self- executable application. One way to check its existence is to type dir Welcome.* and press [Enter] in the prompt. The following shows how the output could be if Welcome.exe is created successfully. It is necessary to note the source code will stay the way it is, which means no change is made to its content, even after compilation. C:\cis218>dir Welcome.* Volume in drive C has no label. Volume Serial Number is 84AF-8E2B Directory of C:\cis218 01/01/2019 10:05 PM 875 Welcome.cs 01/01/2019 10.05 PM 13,824 Welcome.exe After compilation, type Welcome.exe (or simply Welcome) and press [Enter] to run the .exe application. C:\cis218>Welcome.exe The above code, again, is a concole application. In Microsoft’s term, this Welcome.exe program’s “Output File Format” is set to be “DOS-based” which means it must be executed in a Command Prompt (or a DOS envrionment). This kind of program will not work in Windows desktop envrionment. The above console application will generate the following output. C:\cis218> Welcome to CIS218 Visual C#! A later section will discuss the differences between a console and a GUI application. In the next section, the instruction will temporarily jump off the topic to explain what the above source code includes and what its statements mean. It is necessary to note that C# compiler is installed only when a version of Visual Studio (such as Visual Studio Community) is installed to a Windows machine. Without a successful installation of Visual Studio version, the above C# source code cannot be compiled into an .exe application. With the Visual Studio installed in a Windows machine, programmers can launch the Developer Command Prompt (not the regular Window Command Prompt). Windows 10 users need to open the Start menu, press the Windows logo key , and then enter dev on the Start menu to bring a list of installed apps, choose the Developer Command Prompt. By default, the Developer Command Prompt displays the following path after being launched, where “X” is the drive name (such as “C”). X:\Program Files\Microsoft Visual Studio\2017\Community> Basic structure In the following sample code, “Samples” is a user-declared namespace. In C#, “namespace” is of a C# used to control the scope of class and method names. program namespace Samples { class Welcome Visual C# - Penn P. Wu, PhD. 3 { static void Main(string[] args) { System.Console.Write("Welcome to CIS218 Visual C#!"); } } } One namespace can contain multiple classes. However, user-declared namespaces are only useful in larger programming projects. In a small-scale coding project, with or without declaring a namespace does not matter a remarkable difference. The following table compares two C# codes. They produce the same results, yet one has declared namespace while the other does not. With namespace Samples { class Welcome { static void Main(string[] args) { System.Console.Write("Welcome to CIS218 Visual C#!"); } } } Without class Welcome { static void Main(string[] args) { System.Console.Write("Welcome to CIS218 Visual C#!"); } } C# allows programmers to split a class definition. When working on large projects, splitting a class over separate files enables programmers to add codes without having to recreate the source file. Visual Studio uses this approach when it creates Windows Forms, Web service wrapper code, and so on. Another benefit to split a class definition is that multiple programmers to work on it at the same time. By the way, after splitting, each “partial class” is known as a “part”. All the parts must use the partial keyword. All the parts must be available at compile time to form the final type.
Recommended publications
  • Non-Invasive Software Transactional Memory on Top of the Common Language Runtime
    University of Neuchâtel Computer Science Department (IIUN) Master of Science in Computer Science Non-Invasive Software Transactional Memory on top of the Common Language Runtime Florian George Supervised by Prof. Pascal Felber Assisted by Patrick Marlier August 16, 2010 This page is intentionally left blank Table of contents 1 Abstract ................................................................................................................................................. 3 2 Introduction ........................................................................................................................................ 4 3 State of the art .................................................................................................................................... 6 4 The Common Language Infrastructure .................................................................................. 7 4.1 Overview of the Common Language Infrastructure ................................... 8 4.2 Common Language Runtime.................................................................................. 9 4.3 Virtual Execution System ........................................................................................ 9 4.4 Common Type System ........................................................................................... 10 4.5 Common Intermediate Language ..................................................................... 12 4.6 Common Language Specification.....................................................................
    [Show full text]
  • Using Microsoft Visual Studio to Create a Graphical User Interface ECE 480: Design Team 11
    Using Microsoft Visual Studio to Create a Graphical User Interface ECE 480: Design Team 11 Application Note Joshua Folks April 3, 2015 Abstract: Software Application programming involves the concept of human-computer interaction and in this area of the program, a graphical user interface is very important. Visual widgets such as checkboxes and buttons are used to manipulate information to simulate interactions with the program. A well-designed GUI gives a flexible structure where the interface is independent from, but directly connected to the application functionality. This quality is directly proportional to the user friendliness of the application. This note will briefly explain how to properly create a Graphical User Interface (GUI) while ensuring that the user friendliness and the functionality of the application are maintained at a high standard. 1 | P a g e Table of Contents Abstract…………..…………………………………………………………………………………………………………………………1 Introduction….……………………………………………………………………………………………………………………………3 Operation….………………………………………………….……………………………………………………………………………3 Operation….………………………………………………….……………………………………………………………………………3 Visual Studio Methods.…..…………………………….……………………………………………………………………………4 Interface Types………….…..…………………………….……………………………………………………………………………6 Understanding Variables..…………………………….……………………………………………………………………………7 Final Forms…………………....…………………………….……………………………………………………………………………7 Conclusion.…………………....…………………………….……………………………………………………………………………8 2 | P a g e Key Words: Interface, GUI, IDE Introduction: Establishing a connection between
    [Show full text]
  • JAWS® for Windows Training Bundle Outline
    JAWS® for Windows Training Bundle Outline Introduction to the Training • Overview of topics to be covered in the training • Introduction to the DAISY format and why it is being used PlexTalk® Pocket Introduction • Description of physical layout • Basic functions: play/pause audio, fast forward/rewind, navigate by heading, navigate to different books • Specifics on navigating through the training bundle • Inserting, deleting, and moving to bookmarks VictorReader Stream Introduction • Description of physical layout • Basic functions: play/pause audio, fast forward/rewind, navigate by heading, navigate to different books • Specifics on navigating through the training bundle • Inserting, deleting, and moving to bookmarks Meet the Trainers • Introduction by Ryan and Dan Introduction to JAWS • What is JAWS? • What kinds of things are people able to do with it? • Silencing JAWS • Working with different types of computer keyboards o Laptop and desktop keyboards o Changing the JAWS keyboard layout • The JAWS key • Pressing multikey keyboard commands • Keyboard help mode • Opening and closing JAWS Working with Windows® Controls • Menus o Navigating vertically and horizontally o Opening submenus • Dialog boxes and their various controls o Edit, combo, check, radio, button, and slider o Moving through various controls • The JAWS Startup Wizard o Speech rate, JAWS startup options, keyboard layout, virtual ribbon feature, etc. Introduction to Windows • What is Windows and what is an operating system? • Differences between Windows 7 and 8 and why we
    [Show full text]
  • Practical ASP.NET Web API
    Practical ASP.NET Web API Badrinarayanan Lakshmiraghavan Practical ASP.NET Web API Copyright © 2013 by Badrinarayanan Lakshmiraghavan This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher’s location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law. ISBN-13 (pbk): 978-1-4302-6175-9 ISBN-13 (electronic): 978-1-4302-6176-6 Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
    [Show full text]
  • Command Line Interface User Guide for Version 11.0 Copyright © 1994-2017 Dell Inc
    Command Line Interface User Guide for Version 11.0 Copyright © 1994-2017 Dell Inc. or its subsidiaries. All Rights Reserved. Contact Information RSA Link at https://community.rsa.com contains a knowledgebase that answers common questions and provides solutions to known problems, product documentation, community discussions, and case management. Trademarks For a list of RSA trademarks, go to www.emc.com/legal/emc-corporation-trademarks.htm#rsa. License Agreement This software and the associated documentation are proprietary and confidential to EMC, are furnished under license, and may be used and copied only in accordance with the terms of such license and with the inclusion of the copyright notice below. This software and the documentation, and any copies thereof, may not be provided or otherwise made available to any other person. No title to or ownership of the software or documentation or any intellectual property rights thereto is hereby transferred. Any unauthorized use or reproduction of this software and the documentation may be subject to civil and/or criminal liability. This software is subject to change without notice and should not be construed as a commitment by EMC. Third-Party Licenses This product may include software developed by parties other than RSA. The text of the license agreements applicable to third-party software in this product may be viewed on the product documentation page on RSA Link. By using this product, a user of this product agrees to be fully bound by terms of the license agreements. Note on Encryption Technologies This product may contain encryption technology. Many countries prohibit or restrict the use, import, or export of encryption technologies, and current use, import, and export regulations should be followed when using, importing or exporting this product.
    [Show full text]
  • Common Language Infrastructure (CLI) Partitions I to IV
    Standard ECMA-335 December 2001 Standardizing Information and Communication Systems Common Language Infrastructure (CLI) Partitions I to IV Phone: +41 22 849.60.00 - Fax: +41 22 849.60.01 - URL: http://www.ecma.ch - Internet: [email protected] Standard ECMA-335 December 2001 Standardizing Information and Communication Systems Common Language Infrastructure (CLI) Partitions I to IV Partition I : Concepts and Architecture Partition II : Metadata Definition and Semantics Partition III : CLI Instruction Set Partition IV : Profiles and Libraries Phone: +41 22 849.60.00 - Fax: +41 22 849.60.01 - URL: http://www.ecma.ch - Internet: [email protected] mb - Ecma-335-Part-I-IV.doc - 16.01.2002 16:02 Common Language Infrastructure (CLI) Partition I: Concepts and Architecture - i - Table of Contents 1Scope 1 2 Conformance 2 3 References 3 4 Glossary 4 5 Overview of the Common Language Infrastructure 19 5.1 Relationship to Type Safety 19 5.2 Relationship to Managed Metadata-driven Execution 20 5.2.1 Managed Code 20 5.2.2 Managed Data 21 5.2.3 Summary 21 6 Common Language Specification (CLS) 22 6.1 Introduction 22 6.2 Views of CLS Compliance 22 6.2.1 CLS Framework 22 6.2.2 CLS Consumer 22 6.2.3 CLS Extender 23 6.3 CLS Compliance 23 6.3.1 Marking Items as CLS-Compliant 24 7 Common Type System 25 7.1 Relationship to Object-Oriented Programming 27 7.2 Values and Types 27 7.2.1 Value Types and Reference Types 27 7.2.2 Built-in Types 27 7.2.3 Classes, Interfaces and Objects 28 7.2.4 Boxing and Unboxing of Values 29 7.2.5 Identity and Equality of Values 29
    [Show full text]
  • CA Plex C# Best Practices
    CA Plex C# Best Practices Example Document Creating packages and code libraries and managing C# source code and application artifacts CA Plex version 6.1 Created by: In collaboration with IIDEA Solutions and CCH, and assistance from CA. Published with the kind permission of the South Carolina Judicial Department . Packages and .NET Assemblies Best Practices for CA Plex. Contents 1. Introduction ......................................................................................................................................... 3 2. Use of assemblies and modules when creating code libraries ............................................................. 3 3. Creating and using assemblies ............................................................................................................. 4 4. Considerations when packaging your model ....................................................................................... 5 5. Software required on the build server .................................................................................................. 6 6. Modelling C# Code Libraries in Plex .................................................................................................. 7 7. Setting up the build server and installing Cruise Control .................................................................. 10 8. Development life cycle ...................................................................................................................... 20 Appendix ..................................................................................................................................................
    [Show full text]
  • Korean Style Guide
    Korean Style Guide Published: February, 2019 Microsoft Korean Style Guide Contents 1 About this style guide............................................................................................................................................... 4 1.1 Recommended style references .............................................................................................................. 4 2 Microsoft voice .............................................................................................................................................................. 5 2.1 Choices that reflect Microsoft voice ..................................................................................................... 6 2.1.1 Flexibility ........................................................................................................................................................ 6 2.1.2 Word choice................................................................................................................................................. 7 2.1.3 Word-to-word translation.................................................................................................................. 8 2.1.4 Words and phrases to avoid ............................................................................................................ 9 2.1.5 세요 instead of 십시오 ...................................................................................................................... 11 2.2 Sample Microsoft voice text...................................................................................................................
    [Show full text]
  • Programming with Windows Forms
    A P P E N D I X A ■ ■ ■ Programming with Windows Forms Since the release of the .NET platform (circa 2001), the base class libraries have included a particular API named Windows Forms, represented primarily by the System.Windows.Forms.dll assembly. The Windows Forms toolkit provides the types necessary to build desktop graphical user interfaces (GUIs), create custom controls, manage resources (e.g., string tables and icons), and perform other desktop- centric programming tasks. In addition, a separate API named GDI+ (represented by the System.Drawing.dll assembly) provides additional types that allow programmers to generate 2D graphics, interact with networked printers, and manipulate image data. The Windows Forms (and GDI+) APIs remain alive and well within the .NET 4.0 platform, and they will exist within the base class library for quite some time (arguably forever). However, Microsoft has shipped a brand new GUI toolkit called Windows Presentation Foundation (WPF) since the release of .NET 3.0. As you saw in Chapters 27-31, WPF provides a massive amount of horsepower that you can use to build bleeding-edge user interfaces, and it has become the preferred desktop API for today’s .NET graphical user interfaces. The point of this appendix, however, is to provide a tour of the traditional Windows Forms API. One reason it is helpful to understand the original programming model: you can find many existing Windows Forms applications out there that will need to be maintained for some time to come. Also, many desktop GUIs simply might not require the horsepower offered by WPF.
    [Show full text]
  • NET Core 3 and Unit Testing
    Learn C# Programming A guide to building a solid foundation in C# language for writing efcient programs Marius Bancila Rafaele Rialdi Ankit Sharma BIRMINGHAM—MUMBAI Learn C# Programming Copyright © 2020 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every efort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. Commissioning Editor: Richa Tripathi Acquisition Editor: Alok Dhuri Senior Editor: Storm Mann Content Development Editor: Ruvika Rao Technical Editor: Pradeep Sahu Copy Editor: Safs Editing Language Support Editor: Safs Editing Project Coordinator: Francy Puthiry Proofreader: Safs Editing Indexer: Pratik Shirodkar Production Designer: Jyoti Chauhan First published: April 2020 Production reference: 1280420 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78980-586-4 www.packt.com To my smart boys, Cristian and Bogdan, who love learning new things every day.
    [Show full text]
  • For Mac OS X
    C More on Stata for Mac Contents C.1 Using Stata datasets and graphs created on other platforms C.2 Exporting a Stata graph to another document C.3 Stata and the Notification Manager C.4 Stata(console) for Mac OS X C.1 Using Stata datasets and graphs created on other platforms Stata will open any Stata .dta dataset or .gph graph file, regardless of the platform on which it was created, even if it was a Windows or Unix system. Also, Stata for Windows and Stata for Unix users can use any files that you create. Remember that .dta and .gph files are binary files, not text (ASCII) files, so they need no translation; simply copy them over to your hard disk as is. Files created on other platforms can be directly opened in the Command window; for example, you can load a dataset by typing use filename or by double-clicking on the file in the Finder. C.2 Exporting a Stata graph to another document Suppose that you wish to export a Stata graph to a document created by your favorite word processor or presentation application. You have two main choices for exporting graphs: you may copy and paste the graph by using the Clipboard, or you may save the graph in one of several formats and import the graph into the application. C.2.1 Exporting the graph by using the Clipboard The easiest way to export a Stata graph into another application is to use drag and drop. You can select the graph in the Graph window and drag it to the location you would like it in another open application.
    [Show full text]
  • Cataloging User's Guide
    Voyager® 9.2 Cataloging User’s Guide November 2015 Ex Libris Confidential CONFIDENTIAL INFORMATION The information herein is the property of Ex Libris Ltd. or its affiliates and any misuse or abuse will result in economic loss. DO NOT COPY UNLESS YOU HAVE BEEN GIVEN SPECIFIC WRITTEN AUTHORIZATION FROM EX LIBRIS LTD. This document is provided for limited and restricted purposes in accordance with a binding contract with Ex Libris Ltd. or an affiliate. The information herein includes trade secrets and is confidential. DISCLAIMER The information in this document will be subject to periodic change and updating. Please confirm that you have the most current documentation. There are no warranties of any kind, express or implied, provided in this documentation, other than those expressly agreed upon in the applicable Ex Libris contract. This information is provided AS IS. Unless otherwise agreed, Ex Libris shall not be liable for any damages for use of this document, including, without limitation, consequential, punitive, indirect or direct damages. Any references in this document to third-party material (including third-party Web sites) are provided for convenience only and do not in any manner serve as an endorsement of that third-party material or those Web sites. The third-party materials are not part of the materials for this Ex Libris product and Ex Libris has no liability for such materials. TRADEMARKS ʺEx Libris,ʺ the Ex Libris Bridge to Knowledge , Primo, Aleph, Voyager, SFX, MetaLib, Verde, DigiTool, Rosetta, bX, URM, Alma , and other marks are trademarks or registered trademarks of Ex Libris Ltd. or its affiliates.
    [Show full text]