C# Data type Chapter 1.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Air Force Institute of Technology Electrical and Computer Engineering
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 1 Unit 7 Decisions (Cont.) and Message Boxes Chapter.
Section 2 - Selection and Repetition. Equality and Relational Operators.
Chapter 12- GUI Concepts I. 12.1Introduction 12.2 Windows Forms 12.3 Event-Handling Model Basic Event Handling 12.4 Control Properties and Layout.
Object-Oriented Application Development Using VB.NET 1 Chapter 4 VB.NET Programming with Supplied Classes.
Differences between Java and C CS-2303, C-Term Differences between Java and C CS-2303, System Programming Concepts (Slides include materials from.
GUI-Labels, TextBoxes and Buttons Label- displays read-only text Common properties:  Font – font used by the text of label  Text – text to appear on.
Numbers and Arrays. Widening and narrowing Numeric types are arranged in a continuum: double float long int short byte, char You can easily assign a narrower.
Java Syntax Primitive data types Operators Control statements.
Some basic I/O.
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
Repeating Instructions
Computer Science A 2: 6/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
GUI-Labels, TextBoxes and Buttons Label- displays read-only text Label- displays read-only text Common properties: Common properties: Font – font used.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
JAVA PROGRAMMING PART II.
I would like you to develop a mobile application that calculates for me the discount on an item I want to purchase. Input:  User enters in a number for.
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
1 Chapter 1 C# Data type. 2 Install.NET 2003 or 2005 NET 2005 is better than NET 2003 and very friendly for programmer. However, NET 2005 needs NET platform.
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.
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.
1 Advanced Programming IF. 2 Control Structures Program of control –Program performs one statement then goes to next line Sequential execution –Different.
Chapter 3:Decision Structures.  3.1 The if Statement  3.2 The if-else Statement  3.3 The if-else-if Statement  3.4 Nested if Statements  3.5 Logical.
Decisions and Debugging Part06dbg --- if/else, switch, validating data, and enhanced MessageBoxes.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
4.1 Object Operations operators Dot (. ) and new operate on objects The assignment operator ( = ) Arithmetic operators + - * / % Unary operators.
Applications Development
Java Programming Java Basics. Data Types Java has two main categories of data types: –Primitive data types Built in data types Many very similar to C++
Basics and arrays Operators:  Arithmetic: +, -, *, /, %  Relational:, >=, ==, !=  Logical: &&, ||, ! Primitive data types Byte(8), short(16), int(32),
Chapter 2 Variables.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1 Introduction 5.2 Essentials of Counter-Controlled.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Chapter One Lesson Three DATA TYPES ©
A: A: double “4” A: “34” 4.
Chapter 5 Defining Classes II Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
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.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 06 – Java Datatypes Webpage:
Special Methods in Java. Mathematical methods The Math library is extensive, has many methods that you can call to aid you in your programming. Math.pow(double.
 2002 Prentice Hall. All rights reserved. 1 Chapter 4 – Control Structures Part 1 Outline Counter-Controlled Repetition: Example Sentinel-Controlled Repetition:
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
Computer Programs CS 1400 Dennis A. Fairclough Version 1.1 CS 1400 Dennis A. Fairclough Version 1.1.
Week 6: THE C# LANGUAGE Flow Control. Slide 2 Data Types Boolean Byte (0 to 255) Char Date String Decimal Object Short (-32,768 to 32,767) Integer (-2,147,483,648.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Lecture 02 Dr. Eng. Ibrahim El-Nahry Methods. 2 Learning Objectives Class Definition includes both methods and data properties Method Definition and Declaration.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Arrays. What is an array? An array is a collection of data types. For example, what if I wanted to 10 different integers? int num1; int num2; int num3;
Object Oriented Programming Lecture 2: BallWorld.
Input, Output and Variables GCSE Computer Science – Python.
CSIT 108 Review Visual Basic.NET Programming: From Problem Analysis to Program Design.
PictureBox, MessageBox, Multiple Forms, Splash Screens and Timers
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Programming in Java Sachin Malhotra, Chairperson, PGDM-IT, IMS Ghaziabad Saurabh Chaudhary, Dean, Academics, IMS Ghaziabad.
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
Chapter 4 – Fundamental Data Types
Making Decisions and Working With Strings
Apply Procedures to Develop Message, Input, and Dialog Boxes
Week 6: THE C# LANGUAGE Flow Control.
Chapter 2.
Advanced Programming Chapters 5 & 6: Control Structures
Variables, Loops, Decision Statements, etc
Chapter 2 Variables.
Control Structures Part B - Message and Input Boxes
Chapter 5 – Control Structures: Part 2
Welcome back to Software Development!
Agenda Types and identifiers Practice Assignment Keywords in Java
Presentation transcript:

C# Data type Chapter 1

Most of them are same as in C++ Major C# Data Type Type Meaning bool true or false byte 8 bits long sbyte signed byte char Character int 4 bytes integer number short 2 bytes integer number long 8 bytes integer number uint unsigned integer ulong unsigned long integer float 4 bytes decimal number double 8 bytes decimal number Most of them are same as in C++

Some C# Math functions No Math.Random() function Function Meaning Math.Abs(x) Absolute value of x : |x| Math.Sqrt(x) Square root of x Math.Exp(x) Exponential value ex Math.Pow(x, n) Power value xn Math.Log(x) Ln(x): Natural logarithm of x Math.Log10(x) Log10(x): logarithm of x in base of 10 Math.Ceiling(x) The smallest integer bigger or equal to x Math.Floor(x) The largest integer less or equal to x Math.Round(x) Round up integer of x Math.Sin(x) sin(x) similar for cos(x) and tan(x) Math::PI  = 3.14159….. Math.Max(x,y) Maximum of x and y Math.Min(x,y) Minimum of x and y Math.Sign(x) Sign of x No Math.Random() function

Random class Random class object is used to generate random integer, random floating number or random bytes. Random rnd = new Random(); // Random object rnd int n = rnd.Next(); // Random integer int k = rnd.Next()%7; // Random integer 0-6 double d = rnd.NextDouble() // Random double number between 0.0 and 1.0 Byte[] bArray = new Byte[10]; rnd.NextBytes(bArray); // Now bArray is filled with 10 Random bytes

Most operators in C++ are good for C# =, +=, -=, *=, /= //assignment operators ==, != // compare operators <, <=, >, >= +, - //signed operators +, -, *, /, % // math operation ++, -- <<, >> //shift operators &, |, ^ // bitwise AND, OR, XOR The following are new operators Console.Readline() // standard input Console.WriteLine() // standard output

Most Branch operators in C++ are also good for C# if(x>1 && y<2){ } if(a<2 || b>3){ } for loop while loop do while loop switch break in the loop continue in the loop All those operators are exactly same as in C++ or Java Be careful that C# is case sensitive

String object String or string is the most important class: string msg = new string("Hello NET"); string msg = "Hello NET"; char[] charArray = {'H', 'e', 'l', 'l', 'o', ' ', 'N', 'E', 'T'}; string msg = new string(charArray); Operators: string stringCopy(str) int CompareTo(str) int IndexOf(str) int LastIndexOf(str) string ToLower() string ToUpper() Concatenation String msg = "Good" +" Morning"; (use +)

Standard input and output Standard input is: Console.Read(); Console.ReadLine(); Standard output is: string s = "Hello"; Console.ReadLine(s);

MessageBox.Show Other buttons: MessageBox.Show( "Missing data input", // message string "input Error", // title caption string MessageBoxButtons.OK, // button type MessageBoxIcon.Exclamation // icon ); Other buttons: MessageBoxButtons.AbortRetryIgnore MessageBoxButtons.OK MessageBoxButtons.OKCancel MessageBoxButtons.RetryCancel MessageBoxButtons.YesNo MessageBoxButtons.YesNoCancel

Other icons: MessageBoxIcon.Asterisk MessageBoxIcon.Error MessageBoxIcon.Exclamation MessageBoxIcon.Hand MessageBoxIcon.Information MessageBoxIcon.None MessageBoxIcon.Question MessageBoxIcon.Stop MessageBoxIcon.Warning

Return value of MessageBox The return value type of MessageBox.Show() is DialogResult which has the following values: DialogResult.Abort DialogResult.Cancel DialogResult.Ignore DialogResult.No DialogResult.None DialogResult.OK DialogResult.Retry DialogResult.Yes

String Split function Basic usage is public string[] Split(params char[]); string charStr = " ,.:"; char [] charArray = charStr.ToCharArray(); string words = "one two,three:four."; string [] split = word.Split(charArray); Then we can use foreach() to read this string array foreach (string s in split) { Console.WriteLine(s); }

Type converting String to integer uses Int32.Parse(str); String str = "1234"; try { int n = Int32.Parse(str); } catch(FormatException e) Console.WriteLine(e.Message); String to double uses Double.Parse(str)

Array declaration and initialization An integer Array must be defined like: int [] myArray = new int[50]; string [] strs = {"Mike", "John", "Kathy"}; However declarations int myArray [] ; string strs []; are wrong! It means that [] must be before the variable of array. Loop operator foreach foreach(int n in myArray){ } foreach(string s in strs){ } is special for array.

Switch operator can use strings string [] strs = {"Mike", "John", "Kathy"}; foreach(string one in strs) { switch(one) case "Mike": Console.write(one); break; case "John": Console.write(one); case "Kathy": Console.write(one); default: Console.write("Not found"); }