Getting Started with C#.  Name: Ahmed Galib Reza   Lab: Ubiquitous Computing Lab  Nationality: Bangladeshi  Education:

Slides:



Advertisements
Similar presentations
CSci 1130 Intro to Programming in Java
Advertisements

Getting Started with C# 1 SWE 344 Internet Protocols & Client Server Programming.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Constants and Data Types Constants Data Types Reading for this class: L&L,
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Chapter 2 Data Types, Declarations, and Displays
String Escape Sequences
Basic Elements of C++ Chapter 2.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
1 Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class:
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Input & Output: Console
C Tokens Identifiers Keywords Constants Operators Special symbols.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
CS_OOP Lecture #2: Computer Hardware/Software; Variables, C# Data Types, and IO.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Chapter 2: Using Data.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Lecture #5 Introduction to C++
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
C++ Programming: Basic Elements of C++.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
Introduction to Programming
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX.
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Today’s Lecture  Literal  Constant  Precedence rules  More assignment rules  Program Style.
1.2 Primitive Data Types and Variables
Chapter One Lesson Three DATA TYPES ©
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Primitive Data Types 1 In PowerPoint, point at the speaker icon, then click the "Play" button.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
1 A more complex example Write a program that sums a sequence of integers and displays the result. Assume that the first integer read specifies the number.
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Chapter 1.2 Introduction to C++ Programming
Definition of the Programming Language CPRL
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 2: Introduction to C++
Lecture 2 Data Types Richard Gesick.
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Variables A variable is a placeholder for a value. It is a named memory location where that value is stored. Use the name of a variable to access or update.
Multiple variables can be created in one declaration
Computing with C# and the .NET Framework
Chapter 2.
Escape Sequences What if we wanted to print the quote character?
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
C++ Data Types Data Type
Chapter 2: Java Fundamentals
elementary programming
Chapter 2: Introduction to C++.
Visual Programming COMP-315
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Chap 2. Identifiers, Keywords, and Types
Presentation transcript:

Getting Started with C#

 Name: Ahmed Galib Reza   Lab: Ubiquitous Computing Lab  Nationality: Bangladeshi  Education: ◦ B. IT (Hons.) Information System Engineering, Multimedia University, Malaysia. ◦ Master of Computer Engineering, Major in Ubiquitous IT, Dongseo University, South Korea.

 Introduction  Understand the basic structure of a C# program.  Obtain a basic familiarization of what a "Namespace" is.  Obtain a basic understanding of what a Class is.  Learn what a Main method does.  Learn about console input/output (I/O)  Variables and C# Data types  C# Operators

 C# (C Sharp), a successor to C++, has been released in conjunction with the.NET framework.  C# design goals: ◦ Be comfortable for C++ programmer ◦ Fit cleanly into the.NET Common Language Runtime (CLR) ◦ Simplify the C++ model ◦ Provide the right amount of flexibility ◦ Support component-centric development

using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!!"); } Uses the namespace System Entry point must be called Main Output goes to the console File name and class name need not to be identical C# is case sensitive, therefore args and Args are different identifiers Uses the namespace System Entry point must be called Main Output goes to the console File name and class name need not to be identical C# is case sensitive, therefore args and Args are different identifiers Namespace Declaration is Optional

namespace ConsoleApplication1 { class Program { static void Main(string[] args) { System.Console.WriteLine("Hello World!!"); } must use qualified name

 Replace Console.WriteLine() statement of HelloWorld Program by Console.Write() statement.  What is your output?

 Console.Write() ◦ Write the specific string to the standard output stream.  Console.WriteLine() ◦ Write the specific string, follow by current string terminator to the standard output stream.

using System; class Exercise { static void Main() { Console.WriteLine("One!!!"); Console.WriteLine("Two!!!"); Console.WriteLine("Three!!!"); }

What is your Output? Any changes? using System; class Exercise { static void Main() { Console.Write ("One!!!"); Console.Write ("Two!!!"); Console.Write ("Three!!!"); }

 Often we use special identifiers called keywords that already have a predefined meaning in the language ◦ Example: class  A keyword cannot be used in any other way

All C# keywords are Lowercase

 A variable is a typed name for a location in memory  A variable must be declared, specifying the variable's name and the type of information that will be held in it int numberOfStudents; … int average, max; data type variable name int total; … Which ones are valid variable names? myBigVar VAR1 99bottles namespace It’s-all-over numberOfStudents: average: max: total:

 An assignment statement changes the value of a variable  The assignment operator is the = sign total = 55; r You can only assign a value to a variable that is consistent with the variable's declared type (more later)  You can declare and assign initial value to a variable at the same time, e.g., int total = 55; r The value on the right is stored in the variable on the left  The value that was in total is overwritten int total; …

Example static void Main(string[] args) { int total; total = 15; System.Console.Write(“total = “); System.Console.WriteLine(total); total = ; System.Console.Write(“total = “); System.Console.WriteLine(total); }

 A constant is similar to a variable except that it holds one value for its entire existence  The compiler will issue an error if you try to change a constant  In C#, we use the constant modifier to declare a constant constant int numberOfStudents = 42;  Why constants? ◦ give names to otherwise unclear literal values ◦ facilitate changes to the code ◦ prevent inadvertent errors

 There are 15 data types in C#  Eight of them represent integers: ◦ byte, sbyte, short, ushort, int, uint, long,ulong  Two of them represent floating point numbers ◦ float, double  One of them represents decimals: ◦ decimal  One of them represents boolean values: ◦ bool  One of them represents characters: ◦ char  One of them represents strings: ◦ string  One of them represents objects: ◦ object

 The difference between the various numeric types is their size, and therefore the values they can store: Range , ,147,483,648 – 2,147,483,647 0 – 4,294,967,  to 9  – 1.8   1.0  ;  7.9  with significant digits  1.5  ;  3.4  with 7 significant digits  5.0  ;  1.7  with significant digits Type byte sbyte short ushort int uint long ulong decimal float double Storage 8 bits 16 bits 32 bits 64 bits 128 bits 32 bits 64 bits

int x = 1; short y = 10; float pi = 3.14f; // f denotes float float f3 = 7E-02f; // 0.07 double d1 = 7E-100; // use m to denote a decimal decimal microsoftStockPrice = 28.38m;

 A bool value represents a true or false condition  A boolean can also be used to represent any two states, such as a light bulb being on or off  The reserved words true and false are the only valid values for a boolean type bool doAgain = true;

 A char is a single character from the a character set  Character literals are represented in a program by delimiting with single quotes, e.g., 'a‘ 'X‘ '7' '$‘ ',‘ char response = ‘Y’;

Common Escape Sequences

 A string represents a sequence of characters, e.g., string message = “Hello World”;

using System; class Exercise { static void Main() { int CoordX; int CoordY; CoordX = 12; CoordY = -8; Console.Write("Cartesian Coordinate System: "); Console.Write("P("); Console.Write(CoordX); Console.Write(", "); Console.Write(CoordY); Console.WriteLine(")\n"); }

using System; class Exercise { static void Main() { uint DayOfBirth; uint MonthOfBirth; uint YearOfBirth; DayOfBirth = 8; MonthOfBirth = 11; YearOfBirth = 1996; Console.WriteLine("Red Oak High School"); Console.Write("Student Date of Birth: "); Console.Write(MonthOfBirth); Console.Write("/"); Console.Write(DayOfBirth); Console.Write("/"); Console.Write(YearOfBirth); Console.WriteLine(); }

using System; class NumericRepresentation { static void Main() { long CountryArea; CountryArea = L; Console.Write("Country Area: "); Console.Write(CountryArea); Console.Write("km2\n"); }

using System; class NumericRepresentation { static void Main() { float Distance = F; //Distance = F; Console.Write("Distance = "); Console.Write(Distance); Console.WriteLine("km\n"); }

using System; class Exercise { static void Main() { string Team = "Real Madrid"; string Country = "Spain"; Console.WriteLine("Welcome to the World of C# Programming!"); Console.Write("Team: "); Console.WriteLine(Team); Console.Write("Country: "); Console.WriteLine(Country); Console.WriteLine(); }

 Number Number ◦ Example :  double int  intfloat  shortint  String/NumberNumber ◦ Example :  stringint  doublestring

using System; class Exercise { static void Main() { const double PI = 3.14; int integer = (int)PI; string str = Convert.ToString(PI); double doubleValue = Convert.ToDouble(str); Console.WriteLine("const PI is {0}", PI); Console.WriteLine("integer is {0}", integer); Console.WriteLine("str is {0}", str); Console.WriteLine("doubleValue is {0}", doubleValue); }

Category (by precedence) Operator(s)Associativity Primary x.y f(x) a[x] x++ x-- new typeof default checked unchecked delegate left Unary+ - ! ~ ++x --x (T)xleft Multiplicative* / %left Additive+ -left Shift >left Relational = is asleft Equality== !=right Logical AND&left Logical XOR^left Logical OR|left Conditional AND&&left Conditional OR||left Null Coalescing??left Ternary?:right Assignment= *= /= %= += -= >= &= ^= |= =>right

using System; class Binary { public static void Main() { int x, y, result; float floatresult; x = 7; y = 5; result = x+y; Console.WriteLine("x+y: {0}", result); result = x-y; Console.WriteLine("x-y: {0}", result); result = x*y; Console.WriteLine("x*y: {0}", result); result = x/y; Console.WriteLine("x/y: {0}", result); floatresult = (float)x/(float)y; Console.WriteLine("x/y: {0}", floatresult); result = x%y; Console.WriteLine("x%y: {0}", result); result += x; Console.WriteLine("result+=x: {0}", result); } }

using System; class Unary { public static void Main() { int unary = 0; int preIncrement; int preDecrement; int postIncrement; int postDecrement; int positive; int negative; bool logNot; preIncrement = ++unary; Console.WriteLine("pre-Increment: {0}", preIncrement); preDecrement = --unary; Console.WriteLine("pre-Decrement: {0}", preDecrement); postDecrement = unary--; Console.WriteLine("Post-Decrement: {0}", postDecrement); postIncrement = unary++; Console.WriteLine("Post-Increment: {0}", postIncrement); Console.WriteLine("Final Value of Unary: {0}", unary); positive = -postIncrement; Console.WriteLine("Positive: {0}", positive); negative = +postIncrement; Console.WriteLine("Negative: {0}", negative); logNot = false; logNot = !logNot; Console.WriteLine("Logical Not: {0}", logNot); } }

OptionDescription Step IntoIf the current line contains a method, the execution point will traverse deeper into the method definition. Step OverIf the current line contains a method, the execution point will not move further into the method definition Step OutIf the current line is within a method definition, the execution point will move out of the current method and back to the point before calling the method We will discuss in more detail in next class.