Session 02 Module 3: Statements and Operators Module 4: Programming constructs Module 5: Arrays.

Slides:



Advertisements
Similar presentations
Module 4: Statements and Exceptions. Overview Introduction to Statements Using Selection Statements Using Iteration Statements Using Jump Statements Handling.
Advertisements

C# Console Application
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Introduction to the C# Programming Language for the VB Programmer.
Differences between Java and C CS-2303, C-Term Differences between Java and C CS-2303, System Programming Concepts (Slides include materials from.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
C# Programming: From Problem Analysis to Program Design1 Advanced Object-Oriented Programming Features C# Programming: From Problem Analysis to Program.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
11 Values and References Chapter Objectives You will be able to: Describe and compare value types and reference types. Write programs that use variables.
Module 1: Introduction to C# Module 2: Variables and Data Types
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
Programming in C#. I. Introduction C# (or C-Sharp) is a programming language. C# is used to write software that runs on the.NET Framework. Although C#
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Final Exam Review Closed book Closed laptop One sheet of notes permitted SE-0010 Dr. Mark L. Hornick 1.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
STATEMENTS AND FLOW OF EXECUTION CHAPTER 11 OF APRESS A PROGRAMMERS GUIDE TO C SHARP 5.0.
VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
Introduction to Exception Handling and Defensive Programming.
ILM Proprietary and Confidential -
CSc2310 tutoring session, week 8 Fall, 2012 Haidong Xue 5:30pm—8:30pm 11/06/2012 and 11/07/2012 -Test 3 Study Guide.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
C# EMILEE KING. HISTORY OF C# In the late 1990’s Microsoft recognized the need to be able to develop applications that can run on multiple operating system.
Expressions, Conditionals and Looping CS 3260 Version 1.0 CS 3260 Version 1.0.
C++ Lecture 1 Friday, 4 July History of C++ l Built on top of C l C was developed in early 70s from B and BCPL l Object oriented programming paradigm.
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Bill Campbell, UMB Microsoft's.NET C# and The Common Language Runtime.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
CIS 3301 C# Lesson 3 Control Statements - Selection.
1 9/6/05CS360 Windows Programming CS360 Windows Programming.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
1 9/22/05CS360 Windows Programming Arrays, Collections, Hash Tables, Strings.
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
Session 1 C# Basics.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
Introduction to C# Anders Hejlsberg Distinguished Engineer Developer Division Microsoft Corporation.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Session 2 Operators, Decisions and Loops. Objectives Operators Casting data Decision marking structures Loops break, continue, return.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Unit – 3 Control structures. Condition Statements 1.If.…..else :- Has someone ever told you, "if you work hard, then you will succeed"? And what happens.
1 Statements © University of Linz, Institute for System Software, 2004 published under the Microsoft Curriculum License.
Throw, Throws & Try-Catch Statements Explanations and Pictures from: Reference:
1 Handling Errors and Exceptions Chapter 6. 2 Objectives You will be able to: 1. Use the try, catch, and finally statements to handle exceptions. 2. Raise.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
Lecture 11 Dr. Eng. Ibrahim El-Nahry Exception Handling.
INTRODUCTION BEGINNING C#. C# AND THE.NET RUNTIME AND LIBRARIES The C# compiler compiles and convert C# programs. NET Common Language Runtime (CLR) executes.
MIS Professor Sandvig MIS 324 Professor Sandvig
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
Computing with C# and the .NET Framework
Chapter 4 – Control Structures Part 1
Chapter 3: Understanding C# Language Fundamentals
CS360 Windows Programming
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Conditional Statements
Module 2: Understanding C# Language Fundamentals
Java Tokens & Data types
Part B – Structured Exception Handling
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
Objectives Define and describe statements and expressions
Debugging and Handling Exceptions
IS 135 Business Programming
Presentation transcript:

Session 02 Module 3: Statements and Operators Module 4: Programming constructs Module 5: Arrays

Operators & Constructs & Arrays / Session2 / 2 of 42 Module 1 – Review (1) .Net Framework is multi-language platform to build, deploy and run various types of applications  Two major components of.Net Framework is CLR and FCL  When code is written in.Net language such as C#,VB…compiled, output code is converted to code native to operating system by Just-In-Time language

Operators & Constructs & Arrays / Session2 / 3 of 42 Module 1 – Review (2)  C# is an object-oriented programming language derived from c and C++.  C# support features like type-safety checking, garbage collection, ECMA standardization, generics  Visual studio 2005 is complete set of tool to build high performance applications

Operators & Constructs & Arrays / Session2 / 4 of 42 Module 2 – Review (1)  In C#, data types are also divided into two categories: value types and reference types  The predefined data types are referred to as basic data types in C#.  C# supports three types of comments  XML comments are inserted in XML tags. These tags can either be predefined or user- defined.

Operators & Constructs & Arrays / Session2 / 5 of 42 Module 2 – Review (2)  Two output methods: Console.Write() and Console.WriteLine()  Two input methods: Console.Read() and Console.ReadLine()  Convert class is used to convert a variable into another data type.  Some type of format specifiers: number and datatime

Operators & Constructs & Arrays / Session2 / 6 of 42 Module 3 - Objectives  List the statement categories in C#  Identify and explain the use of operators  Explain Boxing and Unboxing

Operators & Constructs & Arrays / Session2 / 7 of 42 Types of Statements  Selection  Iteration  Jump  Exception Handling  Checked and Unchecked  Fixed statement  Lock statement

Operators & Constructs & Arrays / Session2 / 8 of 42 Selection Statements  if - else  switch - case  Tenary or conditional operator ? : ;

Operators & Constructs & Arrays / Session2 / 9 of 42 Iteration Statements  do  for  foreach, in  while

Operators & Constructs & Arrays / Session2 / 10 of 42 Jump Statements  break  continue  default  goto  return  yield

Operators & Constructs & Arrays / Session2 / 11 of 42 Exception Handling  try  catch  finally

Operators & Constructs & Arrays / Session2 / 12 of 42 Checked and Unchecked statements  The checked statement checks for an arithmetic overflow in arithmetic expressions.  An arithmetic overflow occurs if the result of an expression or a block of code is greater than the range of the target variable’s data type.  When overflow, an exception OverflowException is thrown

Operators & Constructs & Arrays / Session2 / 13 of 42 Checked and Unchecked Statements using System; class Addition { public static void Main() { byte numOne = 255; byte numTwo = 1; byte result = 0; try { // This code throws an overflow exception checked { result = (byte)(numOne + numTwo); } Console.WriteLine("Result: " + result); } catch(OverflowException ex) { Console.WriteLine(ex); }

Operators & Constructs & Arrays / Session2 / 14 of 42 Operators  Arithmetic Operators: +, -, *, /, %  Relational Operators: ==, !=, >, =  Logical Operators: &&, ||, ^, &, |  Increment and Decrement Operators: ++, - -  Assignment Operators: +=, -= …  Shift Operators: >  String Concatenation Operator: +  Ternary or Conditional Operator: exp1 ? exp2 : exp3

Operators & Constructs & Arrays / Session2 / 15 of 42 Type casting  C# support two types of casting: implicit explicit

Operators & Constructs & Arrays / Session2 / 16 of 42 Implicit Type Casting

Operators & Constructs & Arrays / Session2 / 17 of 42 Explicit Type Casting  Explicit typecasting refers to changing a data type of higher precision into a data type of lower precision

Operators & Constructs & Arrays / Session2 / 18 of 42 Explicit Type Conversion  Two other ways to implement explicit type conversion Convert class ToString() method

Operators & Constructs & Arrays / Session2 / 19 of 42 Boxing and Unboxing  Using Boxing and Unboxing, a value of any value type can be converted to a reference type and vice-versa  When any value-type is boxed, its value is copied into a new object and the reference to that object is stored.  This new object is stored on the heap

Operators & Constructs & Arrays / Session2 / 20 of 42 Boxing  object o = i;  object o = (object)i;

Operators & Constructs & Arrays / Session2 / 21 of 42 Unboxing  int i = (int)o;

Operators & Constructs & Arrays / Session2 / 22 of 42 Module 3 - Summary

Operators & Constructs & Arrays / Session2 / 23 of 42 Module 4 - Objectives  State the syntax and working… case statement  State the syntax and working of for loop  Describe the go to statement  Describe the break and continue statements

Operators & Constructs & Arrays / Session2 / 24 of 42 The switch Statement Syntax switch(variable) { case value: //Statements break; case value: //Statements break; default: //Statements break; }

Operators & Constructs & Arrays / Session2 / 25 of 42 The switch Statement – Contd… switch(weekday) { case 1: Console.WriteLine (“You have selected Monday”); break; case 2: Console.WriteLine (“You have selected Tuesday”); break; default: Console.WriteLine (“Sunday is the Default choice!”); break; }

Operators & Constructs & Arrays / Session2 / 26 of 42  The while loop iterates through the specified statements till the condition specified is true  Syntax – The while loop The break statement - to break out of the loop at anytime The continue statement - to skip the current iteration and begin with the next iteration

Operators & Constructs & Arrays / Session2 / 27 of 42 Examples using System; class TestLoop { static void Main() { int intRes, intCnt = 1; while (intCnt <= 10) { intRes = intCnt * 5; Console.WriteLine("{0}",intRes); intCnt = intCnt+1; }

Operators & Constructs & Arrays / Session2 / 28 of 42 The do loop Syntax -

Operators & Constructs & Arrays / Session2 / 29 of 42 The for loop Syntax -

Operators & Constructs & Arrays / Session2 / 30 of 42 Jump Statements

Operators & Constructs & Arrays / Session2 / 31 of 42 The “break,continue,goto,return “ statements

Operators & Constructs & Arrays / Session2 / 32 of 42 Module 4 - Summary

Operators & Constructs & Arrays / Session2 / 33 of 42 Module 5 - Objectives  State the syntax of declaring arrays  Describe Array class and its purpose  List the commonly properties and methods in Array class

Operators & Constructs & Arrays / Session2 / 34 of 42 DataType[number of elements] ArrayName; int[6] array1; Arrays  A group of values of similar data type  Belong to the reference type and hence are stored on the heap  The declaration of arrays in C# follow the syntax given below -

Operators & Constructs & Arrays / Session2 / 35 of 42 Single-Dimensional Array

Operators & Constructs & Arrays / Session2 / 36 of 42 Multi-Dimensional Array

Operators & Constructs & Arrays / Session2 / 37 of 42 foreach Statement  The foreach loop in C# is an extension of the for loop.  This loop is used to perform specific actions on collections, such as arrays. foreach(type in ) { // statements }

Operators & Constructs & Arrays / Session2 / 38 of 42 Sample

Operators & Constructs & Arrays / Session2 / 39 of 42 Array Class  The Array class is built-in class in the System namespace and is the base class for all arrays in C#  It provides methods for various tasks such as creating, searching, copying and sorting arrays.

Operators & Constructs & Arrays / Session2 / 40 of 42 Array Class Properties

Operators & Constructs & Arrays / Session2 / 41 of 42 Array Class Methods

Operators & Constructs & Arrays / Session2 / 42 of 42 Module 5 - Summary