Computer and Programming

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

Introduction to Programming
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
Computer Programming Lab(7).
Chapter 2 Review Questions
 2005 Pearson Education, Inc. All rights reserved Introduction.
Hand Crafting your own program By Eric Davis for CS103.
Programming by Example Version 1.0. Objectives Take a small computing problem, and walk through the process of developing a solution. Investigate the.
Computer Science 1620 Loops.
Computer Science 1620 Variables and Memory. Review Examples: write a program that calculates and displays the average of the numbers 45, 69, and 106.
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
1 Lab-1 CSIT-121 Spring 2005 Lab Targets Solving problems on computer Programming in C++ Writing and Running Programs Programming Exercise.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
1 Session-I & II CSIT-121 Spring 2006 Session Targets Introducing the VC++.NET Solving problems on computer Programming in C++ Writing and Running Programs.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Computer Science 1620 Programming & Problem Solving.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
1 Lab-1 CSIT-121 Fall 2004 Lab Targets Solving problems on computer Programming in C++ Writing and Running Programs Programming Exercise.
10 ThinkOfANumber program1July ThinkOfANumber program CE : Fundamental Programming Techniques.
GTECH 731 Lab Session 2 Lab 1 Review, Lab 2 Intro 9/6/10 Lab 1 Review Lab 2 Overview.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Intro to Java Programming  A computer follows the instruction precisely and exactly.  Anything has to be declared and defined before it can be used.
A First Program Using C#
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
C# B 1 CSC 298 Writing a C# application. C# B 2 A first C# application // Display Hello, world on the screen public class HelloWorld { public static void.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Loops: Handling Infinite Processes CS 21a: Introduction to Computing I First Semester,
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan Snd Term Nouf Aljaffan (C) CSC 1201 Course at KSU1.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
1 Special Programming Workshop CSIT-120 Fall 2000 Workshop Targets Solving problems on computer Programming in C++ Writing and Running Programs Programming.
Getting Started with C# August 29, NET Concepts Language Independence Language Integration  your C# program can use a class written in VB Program.
Fundamental Programming: Fundamental Programming Introduction to C++
Introduction to C++ Version 1.1. Topics C++ Structure Primitive Data Types I/O Casting Strings Control Flow.
Chapter 4: Subprograms Functions for Problem Solving Mr. Dave Clausen La Cañada High School.
Static Methods. 2 Objectives Look at how to build static (class) methods Study use of methods calling, parameters, returning values Contrast reference.
Variables When programming it is often necessary to store a value for use later on in the program. A variable is a label given to a location in memory.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
1 FUNCTIONS - I Chapter 5 Functions help us write more complex programs.
Introduction to Visual Basic Programming. Introduction Simple Program: Printing a Line of Text Another Simple Program: Adding Integers Memory Concepts.
1 Programming Environment and Tools VS.Net 2012 First project MSDN Library.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Introduction to simple functions.
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 – Introduction to C# Programming Outline 3.1 Introduction 3.2 Simple Program: Printing a Line.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
GCSE Computing: Programming GCSE Programming Remembering Python.
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Chapter 1: Introduction to Computers and Programming.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Bill Tucker Austin Community College COSC 1315
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
C# Programming: From Problem Analysis to Program Design
Advanced Programming Lecture 02: Introduction to C# Apps
Programming Funamental slides
Chapter 3 – Introduction to C# Programming
IS 135 Business Programming
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

01204111 Computer and Programming Introduction to C# 01204111 Computer and Programming

Agenda Why two languages? Differences between Python and C# C# overview Event-driven programming

Why Two Languages? There exist many languages which are quite different from each other Python is easy for beginners, but its flexibility makes it different from other languages you will likely use The two languages were carefully chosen so that they have distinct syntax So you will see and learn various programming styles

What does this program do? Our First C# Program What does this program do? using System; class Program {   public static void Main(string[] args)   {     Random r = new Random();     int answer = 1 + (r.Next() % 100);     int g;     do {       Console.Write("Guess a number: ");       g = int.Parse(Console.ReadLine());       if(g > answer)         Console.WriteLine("Too large");       else if(g < answer)         Console.WriteLine("Too small");     } while(g != answer);     Console.WriteLine("That's correct");   } }

The main program is contained in a function (method) called Main Dissect The Program using System; class Program {   public static void Main(string[] args)   {     Random r = new Random();     int answer = 1 + (r.Next() % 100);     int g;     do {       Console.Write("Guess a number: ");       g = int.Parse(Console.ReadLine());       if(g > answer)         Console.WriteLine("Too large");       else if(g < answer)         Console.WriteLine("Too small");     } while(g != answer);     Console.WriteLine("That's correct");   } } The main program is contained in a function (method) called Main

A pair of braces { } are used to specify a block of code Dissect The Program using System; class Program {   public static void Main(string[] args)   {     Random r = new Random();     int answer = 1 + (r.Next() % 100);     int g;     do {       Console.Write("Guess a number: ");       g = int.Parse(Console.ReadLine());       if(g > answer)         Console.WriteLine("Too large");       else if(g < answer)         Console.WriteLine("Too small");     } while(g != answer);     Console.WriteLine("That's correct");   } } A pair of braces { } are used to specify a block of code

Dissect The Method Main   public static void Main(string[] args)   {     Random r = new Random();     int answer = 1 + (r.Next() % 100);     int g;     do {       Console.Write("Guess a number: ");       g = int.Parse(Console.ReadLine());       if(g > answer)         Console.WriteLine("Too large");       else if(g < answer)         Console.WriteLine("Too small");     } while(g != answer);     Console.WriteLine("That's correct");   } Randomly pick a number between 1 - 100

Dissect The Method Main   public static void Main(string[] args)   {     Random r = new Random();     int answer = 1 + (r.Next() % 100);     int g;     do {       Console.Write("Guess a number: ");       g = int.Parse(Console.ReadLine());       if(g > answer)         Console.WriteLine("Too large");       else if(g < answer)         Console.WriteLine("Too small");     } while(g != answer);     Console.WriteLine("That's correct");   } Repeat as long as g != answer

Dissect The Method Main   public static void Main(string[] args)   {     Random r = new Random();     int answer = 1 + (r.Next() % 100);     int g;     do {       Console.Write("Guess a number: ");       g = int.Parse(Console.ReadLine());       if(g > answer)         Console.WriteLine("Too large");       else if(g < answer)         Console.WriteLine("Too small");     } while(g != answer);     Console.WriteLine("That's correct");   } Print a string, then read an integer and store it in the variable g

Dissect The Method Main   public static void Main(string[] args)   {     Random r = new Random();     int answer = 1 + (r.Next() % 100);     int g;     do {       Console.Write("Guess a number: ");       g = int.Parse(Console.ReadLine());       if(g > answer)         Console.WriteLine("Too large");       else if(g < answer)         Console.WriteLine("Too small");     } while(g != answer);     Console.WriteLine("That's correct");   } Compare g and answer, then display the hint

Dissect The Method Main   public static void Main(string[] args)   {     Random r = new Random();     int answer = 1 + (r.Next() % 100);     int g;     do {       Console.Write("Guess a number: ");       g = int.Parse(Console.ReadLine());       if(g > answer)         Console.WriteLine("Too large");       else if(g < answer)         Console.WriteLine("Too small");     } while(g != answer);     Console.WriteLine("That's correct");   } Tell the user that the answer is correct

Dissect The Program: Outer Block using System; class Program {   public static void Main(string[] args)   {     Random r = new Random();     int answer = 1 + (r.Next() % 100);     int g;     do {       Console.Write("Guess a number: ");       g = int.Parse(Console.ReadLine());       if(g > answer)         Console.WriteLine("Too large");       else if(g < answer)         Console.WriteLine("Too small");     } while(g != answer);     Console.WriteLine("That's correct");   } } Indicate that this program will use functions from standard library

Every method must reside in a class Dissect The Program using System; class Program {   public static void Main(string[] args)   {     Random r = new Random();     int answer = 1 + (r.Next() % 100);     int g;     do {       Console.Write("Guess a number: ");       g = int.Parse(Console.ReadLine());       if(g > answer)         Console.WriteLine("Too large");       else if(g < answer)         Console.WriteLine("Too small");     } while(g != answer);     Console.WriteLine("That's correct");   } } Every method must reside in a class

Coding in Different Languages Hello, May I have a fried rice, and water please? Bonjour, Puis-je avoir un riz frit, et de l'eau s'il vous plaît? Solving the same task using a different language usually has on the same flow of thought and steps. The only differences are syntax and wording.

C# Program Structure C# uses braces { } to specify scopes of things using System; namespace Sample { class Program static void Main() Console.WriteLine("Hello, world"); } C# uses braces { } to specify scopes of things Program on the left contains namespace Sample class Program method Main

C# Program Structure C# statements are contained in a bigger structure using System; namespace Sample { class Program static void Main() Console.WriteLine("Hello, world"); } C# statements are contained in a bigger structure Statements are inside a method Methods are inside a class Classes may or may not be inside a namespace

The Universe of C# Programs Namespace System Namespace Sample (Our own namespace) Class X Class Console WriteLine Class Float Write ReadLine Class Program Class Integer Class Random Parse Main Next ToString … Class Y

using System The statement using System; at the beginning of the program indicates that our program will use the System namespace as our own namespace using System; namespace Sample { class Program …… } Namespace System Namespace Sample (Our own namespace) Class Program Main Class Console WriteLine ReadLine Write Class Integer Parse ToString Class Random Next Class Float

The Main Program: Method Main using System; namespace Sample { class Program static void Main() } The program always starts at the method Main We will write our main program here.

Just Ignore Them (For Now) What are classes? What is this "static void" thing? We will not answer these questions at the moment. For the time being, just use them as shown. You will know when the time comes…

Example: Distance Calculation A still object starts moving in a straight line with the acceleration of a m/s2 for t seconds. How far is it from its starting point?

Developing C# Programs We will use a tool called Integrated Development Environment, or IDE Allows code editing, testing, and debugging Similar to WingIDE We will first start with text-only programs Also known as console applications

Start Writing Program The IDE we will be using is call SharpDevelop. Microsoft Visual Studio Express can also be used.

Create a Solution A program is called a solution Choose New Solution Choose Console Application Enter solution name Once done, stub code will be created

IDE Window Code editor is located at the center of the window Other parts show properties and structure of the program

Identify similarities and differences, compared to a Python program First Program using System; namespace mecha1 {   class Program   {     public static void Main(string[] args)     {       double a, t, s;              Console.Write("Enter a: ");       a = double.Parse(Console.ReadLine());       Console.Write("Enter t: ");       t = double.Parse(Console.ReadLine());              s = a*t*t/2.0;              Console.WriteLine("Distance = {0}", s);     }   } } Identify similarities and differences, compared to a Python program

Every statement ends with a ; First Program using System; namespace mecha1 {   class Program   {     public static void Main(string[] args)     {       double a, t, s;              Console.Write("Enter a: ");       a = double.Parse(Console.ReadLine());       Console.Write("Enter t: ");       t = double.Parse(Console.ReadLine());              s = a*t*t/2.0;              Console.WriteLine("Distance = {0}", s);     }   } } Every statement ends with a ; (semi-colon)

First Program using System; namespace mecha1 {   class Program   {     public static void Main(string[] args)     {       double a, t, s;              Console.Write("Enter a: ");       a = double.Parse(Console.ReadLine());       Console.Write("Enter t: ");       t = double.Parse(Console.ReadLine());              s = a*t*t/2.0;              Console.WriteLine("Distance = {0}", s);     }   } } Variables must be declared with proper data types before used. Here, double is a data type for storing a real number.

Calculate the result and store it in s First Program using System; namespace mecha1 {   class Program   {     public static void Main(string[] args)     {       double a, t, s;              Console.Write("Enter a: ");       a = double.Parse(Console.ReadLine());       Console.Write("Enter t: ");       t = double.Parse(Console.ReadLine());              s = a*t*t/2.0;              Console.WriteLine("Distance = {0}", s);     }   } } Calculate the result and store it in s

First Program Output Statements using System; namespace mecha1 {   class Program   {     public static void Main(string[] args)     {       double a, t, s;              Console.Write("Enter a: ");       a = double.Parse(Console.ReadLine());       Console.Write("Enter t: ");       t = double.Parse(Console.ReadLine());              s = a*t*t/2.0;              Console.WriteLine("Distance = {0}", s);     }   } } Output Statements

Input Statement reads user input as a string First Program using System; namespace mecha1 {   class Program   {     public static void Main(string[] args)     {       double a, t, s;              Console.Write("Enter a: ");       a = double.Parse(Console.ReadLine());       Console.Write("Enter t: ");       t = double.Parse(Console.ReadLine());              s = a*t*t/2.0;              Console.WriteLine("Distance = {0}", s);     }   } } Input Statement reads user input as a string

Convert string into real number (double) First Program using System; namespace mecha1 {   class Program   {     public static void Main(string[] args)     {       double a, t, s;              Console.Write("Enter a: ");       a = double.Parse(Console.ReadLine());       Console.Write("Enter t: ");       t = double.Parse(Console.ReadLine());              s = a*t*t/2.0;              Console.WriteLine("Distance = {0}", s);     }   } } Convert string into real number (double)

Difference: Use { } To Indicate Blocks Python C# def main(): n = int(input()) i = 1 while i <= n: if i % 3 == 0: print(i) // // Other parts are omitted static void Main() { int n = int.Parse(Console.ReadLine()); int i = 1; while(i <= n) if(i % 3 == 0) Console.WriteLine(i); } Python uses indentation C# uses { }

Difference: Use { } To Indicate Blocks // // Other parts are omitted static void Main() { int n = int.Parse(Console.ReadLine()); int i = 1; while(i <= n) if(i % 3 == 0) Console.WriteLine(i); } C# // // Other parts are omitted static void Main() { int n = int.Parse(Console.ReadLine()); int i = 1; while(i <= n) if(i % 3 == 0) Console.WriteLine(i); } C# Indentations have no effect on program logic. They are used for improving readability.

Difference: Use { } To Indicate Blocks // // Other parts are omitted static void Main() { int n = int.Parse(Console.ReadLine()); int i = 1; while(i <= n) if(i % 3 == 0) Console.WriteLine(i); } C# // // Other parts are omitted static void Main() { int n = int.Parse(Console.ReadLine()); int i = 1; while(i <= n) if(i % 3 == 0) Console.WriteLine(i); } C# For control statements such as while or if, omitting { } means the following block contains only one statement.

Difference: Variable Declaration Python C# n = int(input()) total = 0 i = 0 while i < n: x = int(input()) total += x i += 1 print(total) // // Other parts are omitted static void Main() { int n = int.Parse(Console.ReadLine()); int total = 0; int i = 0; int x; while(i < n) x = int.Parse(Console.ReadLine()); total += x; i += 1; }

Declaring Variables Syntax: Ex: <Data type> <Variable name>; <Data type> <Var name>, <Var name>, …; Ex: Initial values can be given right away Ex: Single var Multiple vars. double area; int radius, counter; bool isOkay; int k = 200; bool done = false;

Basic Data Types in C# Type Size Description Range bool 1 byte Store truth value true / false char Store one character character code 0 – 255 byte Store positive integer 0 – 255 short 2 byte Store integer -32,768 -- 32,767 int 4 byte -2.1 x 109 -- 2.1 x 109 long 8 byte -9.2 x 1018 -- 9.2 x 1018 double 16 byte Store real number ± 5.0x10-324 -- ± 1.7x10308 string N/A Store sequence of characters

Computing Summation Write a program that takes a list of positive integers from user until -1 is entered, then displays the sum of all the numbers in the list

Summation: Python total = 0 num = 0 while num != -1: num = int(input()) if num != -1: total += num print(total)

Summation: C# Summation program written in C# static void Main() { int total = 0; int num = 0; while(num != -1) num = int.Parse(Console.ReadLine()); if(num != -1) total += num; } Console.WriteLine(total); total = 0 num = 0 while num != -1: num = int(input()) if num != -1: total += num print(total)

C# and Python: Difference Summary Use { } to indicate blocks Variables Must always be declared with data type specified One variable can store one data type Usually run faster Use indentation for blocks Variables Can be used instantly Each variable can store any data type, which can be changed during the program execution Usually run slower

Cost and Benefit We lose many flexibilities in C#, but more errors can be found much earlier

Erroneous Python Program x = int(input("Enter price: ")) if x <= 10: print("You have to pay",x,"baht.") else: print("You have to pay",y*0.95,"baht.") Do you spot the error? Enter price: 7 You have to pay 7 baht. We will know only when the erroneous line gets executed Enter price: 20 Traceback (most recent call last): File "<string>", line 5, in <fragment> builtins.NameError: name 'y' is not defined

Erroneous C# Program Do you spot the error?     public static void Main(string[] args)     {       double x;       Console.Write("Enter price: ");       x = double.Parse(Console.ReadLine());       if(x <= 10)         Console.WriteLine("You have to pay {0} baht.", x);       else         Console.WriteLine("You have to pay {0} baht.", y*0.95);             } Do you spot the error? This C# program will not compile. The compiler will report The name 'y' does not exist in the current context.

Erroneous Python Program x = input("Enter price: ") if x <= 10: print("You have to pay",x,"baht.") else: print("You have to pay",x*0.95,"baht.") Do you spot the error? There is a problem because we try to compare an integer with a string Traceback (most recent call last): File "<string>", line 2, in <fragment> builtins.TypeError: unorderable types: str() <= int() We will know only when the erroneous line gets executed

This C# program won't compile. Two errors will be reported Erroneous C# Program     public static void Main(string[] args)     {       String x;       Console.Write("Enter price: ");       x = Console.ReadLine();       if(x <= 10)         Console.WriteLine("You have to pay {0} baht.", x);       else         Console.WriteLine("You have to pay {0} baht.", x*0.95);             } Do you spot the error? This C# program won't compile. Two errors will be reported 1. Operator '<=' cannot be applied to operands of type 'string' and 'int'. 2. Operator '*' cannot be applied to operands of type 'string' and 'double'

Choosing a Language Strict Generous Unintentional errors caught before the program starts Longer programs cause more difficulties More limitations Generous Easy and faster to write program, with more flexibility Errors might be found after the program started Can be a problem with large programs

Justification of This Course This course begins with Python, which is easy for beginners The second half uses C#, which has more restrictions, so we write more organized programs This is to allow students to understand the programming concept, without being tied to a specific language

Your Choices There are many other programming languages Most importantly, pick the right tool for the right job

Executing a Program: Review We write a program in a high-level language But the CPU understands only machine language There must be a process of translating what we wrote into something the CPU understands

Executing a C# Program C# Compiler C# Program Executable Code C# programs are compiled by a compiler into a form that can be executed by the computer However, certain software infrastructure must also be installed in the computer

Graphic User Interface C# development environment provides great convenience for creating applications (programs) that interact with users graphically Such applications are said to contain GUI (graphics user interface); they are called GUI applications Let's build a simple GUI application

Typical GUI Applications Click here Edit here Click here Click here Click here Edit here Click here Users can interact with the program in many different ways Therefore, the sequence of execution is not certain, compared to console applications

Writing a GUI Program (1) Consider a program that reads a set of data In a GUI program, user may enter values in many different orders Coding in sequential style is therefore not suitable in GUI programs int w = int.Parse(Console.ReadLine()); int h = int.Parse(Console.ReadLine()); Console.Write("Choose unit: "); string u = Console.ReadLine(); Console.Write("Choose background:"); string b = Console.ReadLine();

Writing a GUI Program (2) As there are various ways user can interact with the program, a piece of code is written to handle each particular event This is called event-driven programming What to do when this button is clicked? What to do when this button is clicked? What to do when this button is clicked? What to do when this value changes? What to do when this value changes?

Event-Driven Programming We will write a program that responds to an event When an event of interest occurs, the corresponding part of program will be executed Consider the following program The program responds to the button click as follows: If this button is clicked" Change the text above to "Sawaddee"

Create a Solution Choose New solution Choose Windows Application Enter the solution's name

User Interface Design Once we create a Windows application We will be able to click on the Design tab to design our window layout for the user interface Click "Design" Click "Tools"

Hello, world Buttons and labels, available in the Tools tab, can be placed on the window. There properties can also be modified via the Properties box. Caution: do not double-click. If you do and the code window shows up, click Design to go back to the design screen.

Objects on the Window We have already placed two objects The IDE sets default names to the objects as follows: These names can be changed, but we will stick to them for now label1 button1

Objects and Their Properties Each object on the window has editable properties. E.g., the button1 object has some properties shown in the right

Properties The Properties tab allows us to adjust text, text font, color, etc. Change the font by editing Font property Change the text by editing the Text property

Writing the Program We will write the program so that the text "Hello, world" is displayed at label1 when the button button1 is clicked In the design window, double click button1 The design window will disappear. The IDE will display code that allows you to edit

We will write our program in this Button1Click method Writing the Program We will write our program in this Button1Click method

Change the text on label1 to "Sawaddee" Handling the Event We write an event-handling method as follows: void Button1Click(object sender, EventArgs e) {   label1.Text = "Sawaddee"; } Change the text on label1 to "Sawaddee" Calls Button1Click Click

Binding Event to Method We can bind any method to the Click event from the Properties box However, by double clicking an object, the IDE will automatically create a new method to handle the object's default event.

Adding Numbers Let us write a program that takes two integers, then displays their sum We start with the user interface design, which consists of a button, two text boxes, and a label

User Interface Design New Solution, choose Windows Application Place objects on the design window as shown text box label text box button

Object Names IDE will automatically assign names for referring to those objects as shown textBox1 label1 textBox2 button1

Watch out the lower/upper cases Choose Better Names The default names do not make a lot of sense. That will make our program difficult to read So we replace them with better ones xTextBox resultLabel yTextBox addButton Watch out the lower/upper cases

Change the name by editing the Name property. Changing Names Change the name by editing the Name property. These names are used to refer to the objects and their properties in our program.

Handling Button Click In the design window, double click the button, then enter the following method void AddButtonClick(object sender, EventArgs e) { int x = int.Parse(xTextBox.Text);   int y = int.Parse(yTextBox.Text);   int result = x + y;   resultLabel.Text = result.ToString(); }

Thinking Corner Add another button to multiply the two numbers