Visual Studio.NET.NET Framework. Web Services Web Forms Windows Forms. Data and XML classes. Framework Base Classes. Common Language Runtime

Similar documents
DAD Lab. 1 Introduc7on to C#

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Chapter 1 Getting Started

Introduce C# as Object Oriented programming language. Explain, tokens,

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations

Introduction to Programming Using Java (98-388)

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

C#: framework overview and in-the-small features

CS2141 Software Development using C/C++ C++ Basics

Getting started 7. Storing values 21. Creating variables 22 Reading input 24 Employing arrays 26 Casting data types 28 Fixing constants 30 Summary 32

Presented By : Gaurav Juneja

Programming refresher and intro to C programming

Introduction to C# Applications

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

Developing for Mobile Devices Lab (Part 1 of 2)

Short Notes of CS201

CS111: PROGRAMMING LANGUAGE II

CS201 - Introduction to Programming Glossary By

.Net Technologies. Components of.net Framework

DigiPen Institute of Technology

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Introduction To C#.NET

CS 61C: Great Ideas in Computer Architecture Introduction to C

Visual C# Instructor s Manual Table of Contents

Class Information ANNOUCEMENTS

PROGRAMMING FUNDAMENTALS

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.

Topic 6: A Quick Intro To C

C Introduction. Comparison w/ Java, Memory Model, and Pointers

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Chapter 1: A First Program Using C#

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

SWE344. Internet Protocols and Client-Server Programming

Start Visual Studio, start a new Windows Form project under the C# language, name the project BalloonPop MooICT and click OK.

Introduction to Java

C++\CLI. Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017

Used to write.net software Software that targets the.net Framework is called managed code

A Comparison of Visual Basic.NET and C#

CALCULATOR APPLICATION

Tutorial 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic

COMP 202 Java in one week

Pace University. Fundamental Concepts of CS121 1

Object Oriented Programming Exception Handling

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

COT 3530: Data Structures. Giri Narasimhan. ECS 389; Phone: x3748

Outline. Object Oriented Programming. Course goals. Staff. Course resources. Assignments. Course organization Introduction Java overview Autumn 2003

BLM2031 Structured Programming. Zeyneb KURT

A Fast Review of C Essentials Part I

Chapter 6. Simple C# Programs

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige

C# Fundamentals. built in data types. built in data types. C# is a strongly typed language

CSC 1214: Object-Oriented Programming

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

12/14/2016. Errors. Debugging and Error Handling. Run-Time Errors. Debugging in C# Debugging in C# (continued)

PES INSTITUTE OF TECHNOLOGY

INFORMATICS LABORATORY WORK #2

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

Engr 123 Spring 2018 Notes on Visual Studio

Tokens, Expressions and Control Structures

Question And Answer.

BASIC ELEMENTS OF A COMPUTER PROGRAM

McGill University School of Computer Science COMP-202A Introduction to Computing 1

C# Fundamentals. Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh

Computer Components. Software{ User Programs. Operating System. Hardware

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Chapter 2: Using Data

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

Introduction to C# Applications Pearson Education, Inc. All rights reserved.

CS 376b Computer Vision

EMBEDDED SYSTEMS PROGRAMMING Language Basics

Chapter 2. Ans. C (p. 55) 2. Which is not a control you can find in the Toolbox? A. Label B. PictureBox C. Properties Window D.

MPATE-GE 2618: C Programming for Music Technology. Syllabus

Java An Introduction. Outline. Introduction

CHAPTER 7 OBJECTS AND CLASSES

CHAPTER 7 OBJECTS AND CLASSES

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Variables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content

Selected Java Topics

Course information. Petr Hnětynka 2/2 Zk/Z

Language Specification

Getting started with Java

An overview of Java, Data types and variables

The Open Core Interface SDK has to be installed on your development computer. The SDK can be downloaded at:

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

Getting started with Java

UNIT I An overview of Programming models Programmers Perspective

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Outline. Introduction to Java. What Is Java? History. Java 2 Platform. Java 2 Platform Standard Edition. Introduction Java 2 Platform

Transcription:

Intro C# Intro C# 1 Microsoft's.NET platform and Framework.NET Enterprise Servers Visual Studio.NET.NET Framework.NET Building Block Services Operating system on servers, desktop, and devices Web Services Web Forms Windows Forms Data and XML classes Framework Base Classes Common Language Runtime

Using Visual Studio.NET Intro C# 2 Create a project -- projects are directories where you can have a single application solutions are directories for many projects (subdirectories) File New Project select "Windows Application" for Designer use "Empty Project" for console application select a disk location specify a name for the directory directory (432?) don't check create a solutions Create or view a source file or with "empty project" Project Add New Item under Local Project Items select Code file and provide a name (p2.cs?) with "windows application" View code (F7)

example Intro C# 3

design view Intro C# 4 In design view right click form to set properties Project creates several files: Program.cs Form1.cs Form1.Designer.cs Can be renamed. Program.cs is the starting point of application. Application logic Form1.cs is a partial class for the GUI Form1.Designer is a partial class that contains InitializeComponents() the method where Toolbox places code of "drag & drop" interface building.

Intro C# 5 With "empty project" in the System Explorer (left most selection area) right click on References. In dialog select to add(if not present): System.dll System.Drawing.dll System.WindowsForms.dll You now have an empty code file in a project. Edit / enter text With "windows application" your development environment will start with Designer Toolbox -- a "draw your interface" tool. With this approach your *.dlls are set for you. Both projects: Use Build to compile (build) and Debug (to run without debugger). Hello432 project I deleted Program.cs and Form1.cs and From either the Project Add existing item menu option or by right clicking on the Hello432 item in the Solution Explorer and selecting Add to add the file Hello432.cs (from visual studio 2003 )

code view Intro C# 6 Solution Explorer right click *.cs select view code to edit Build menu to compile Debug menu to run Compile messages in output. Click errors to select in code window

Hello432.cs "extends" Intro C# 7 /*Introductory Hello CS432 C# project in Windows Forms * uses console output to show program execution. * Comparable to Smalltalk hello432.st example. * * Mike Barnes 2/24/03 */ using System; using System.Drawing; using System.Windows.Forms; class Hello432 : Form { Button b; int clickcount; string blabel; bool bstate; Random rand; construct the application framework and execute it public static void Main() { System.Console.WriteLine("Main: enter"); Application.Run(new Hello432()); System.Console.WriteLine("Main: leave"); }

Intro C# 8 public Hello432() { System.Console.WriteLine("Hello432: enter"); Width = 100; // set size of form Height = 50; blabel = "Hello CS 432!"; // initialize blabel1 value bstate = true; // initialize boolean button state clickcount = 0; // initialize clickcount // create random object and initialize from system time rand = new Random((int)DateTime.Now.Ticks); b = new Button(); // create button b.parent = this; b.text= blabel; b.dock = DockStyle.Fill; b.click += new EventHandler(ButtonOnClick); System.Console.WriteLine("Hello432: leave"); } add an event "listener"

/// <summary> /// Get and return a random bright color /// (upper third 0..255 range) /// An example of UML tagged auto documentation. /// </summary> Intro C# 9 Color RandBrightColor() { int r,g,b; r = rand.next(171, 255); g = rand.next(171, 255); b = rand.next(171, 255); return Color.FromArgb(r, g, b); } Static class and method

Event handler methods respond to events. They always have 2 arguments Intro C# 10 // process button clicks void ButtonOnClick(object obj, EventArgs e) { System.Console.WriteLine("ButtonOnClick: enter"); clickcount++; if (clickcount == 10) { // Okay enough button clicks, shut down System.Console.WriteLine("ButtonOnClick: Close()."); Close(); } // closes window terminates program if (bstate) b.text = "press me again " + clickcount.tostring(); else b.text = blabel; b.backcolor = RandBrightColor(); bstate =!bstate; System.Console.WriteLine("ButtonOnClick: leave," + "bstate = " + bstate.tostring()); }

Intro C# 11 To compile using the command line.net Foundantion SDK csc Hello432.cs // multiple *.cs files csc *.cs You may have to set the search path on your system. To run in the CS Dept. labs you may have to go to the Debug or Release directory and double click on the exe file. We may not have "debugger" system rights in these labs...

Hypertext SDK documentation Intro C# 12

Some C# differences from C++ and Java Intro C# 13 "using" for namespaces instead of "import" for packages namespaces are compiled classes stored in DLLs (base classes) "Main" is uppercase "bool" instead of "boolean" Console.WriteLine("...") not System.out.println("...") can have argument substitution and formatting like C printf Console.WriteLine("iArray[{0}] == {1}", i, iarray[i]); The arguments are substituted by index {0, 1} thus an index can be reusued in the format specification string. using System; class WriteLine { public static void Main() { int i = 20; System.Console.WriteLine("show arg 3 times:\n" + "\t first = {0} \t second = {0} \t third = {0}", i);} } show arg 3 times: first = 20 second = 20 third = 20

C# overview C# language incorporates, builds upon, and extends concepts in C++ and Java. Intro C# 14 Most types, arithmetic operators, and structured statements are the same. char, short, int, long, double + - * / % Implicitly casts from a simpler type to a more complex (no loss of info). Must explicitly cast from complex to simpler type ( possible loss). float f; int i, j = 20;... f = j; i = (int) f; Value types (built in, primitive) stored on run time stack (local, args) Reference types (objects) are allocated (new) on the heap. C# has garbage collection.

Constants, enums Intro C# 15 const type identifier = value; const int dimensions = 3; Once declared and initialized value cannot be changed. Enumerations: typed named constants enum identifier [:base-type] { enumeration list }; enum grades { f = 0, d = 1, c = 2, b = 3, a = 4 }; base-types must be of integral types { ushort, short, int, uint, long, ulong } can't be char. Useful with GUI controls settings and return values.

Safer if && switch int count = 2; if (count = 0)...; // if (count == 0)... A valid C++ conditional statement that assigns 0 to count. Intro C# 16 C# if expression accept only boolean values and there is no automatic conversion of bool to int -- compile time error. Switch does not have automatically fall through for all cases. switch ( switch expression ) { case case1 : // valid case case2 : statement; // compile error case case3 : statement; goto case4; // valid, goto case1! case case4 : statement; break; case case5 : statement; [ default : statement; ] } Switch expression: integral type, char, enum, or string type

foreach Easy iteration through a collection Intro C# 17 foreach ( type identifier in expression) statement; using System; public isn't needed for Main class SeeArgs { static void Main(string [] args) { System isn't needed int i = 0; foreach (string token in args) Console.WriteLine("Arg {0} is {1}", i++, token); } }