The C# language fundamentals ( I ) P.F. Tsai. Hello World Project Please follow the instructions mentioned in the previous class to build a hello world.

Slides:



Advertisements
Similar presentations
2. C# Language Fundamentals
Advertisements

IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Computer Programming w/ Eng. Applications
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Chapter 2 Review Questions
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
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.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Introduction to Computers and Programming Lecture 7:
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
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.
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
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.
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
VARIABLES AND TYPES CITS1001. Types in Java the eight primitive types the unlimited number of object types Values and References The Golden Rule Scope.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
CSCE 121: Introduction to Program Design and Concepts, Honors Dr. J. Michael Moore Spring 2015 Set 3: Objects, Types, and Values 1 Based on slides.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
Basic Notions Review what is a variable? value? address? memory location? what is an identifier? variable name? keyword? what is a legal identifier? what.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Chapter 2: Using Data.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Java Simple Types CSIS 3701: Advanced Object Oriented Programming.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
CS-1030 Dr. Mark L. Hornick 1 C++ Language Basic control statements and data types.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
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.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
The character data type char. Character type char is used to represent alpha-numerical information (characters) inside the computer uses 2 bytes of memory.
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,
Copyright Curt Hill Variables What are they? Why do we need them?
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
Chapter 2 Variables.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
COMP Primitive and Class Types Yi Hong May 14, 2015.
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Object Oriented Software Development 4. C# data types, objects and references.
Variables and Strings. Variables  When we are writing programs, we will frequently have to remember a value for later use  We will want to give this.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
LESSON 5 – Assignment Statements JAVA PROGRAMMING.
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.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Object Oriented Programming Lecture 2: BallWorld.
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.
C++ Lesson 1.
Chapter Topics The Basics of a C++ Program Data Types
Chapter 2 Basic Computation
Java Variables and Types
Basic Elements of C++.
Object Oriented Programming
CSE 143 Introduction to C++ [Appendix B] 4/11/98.
Basic Elements of C++ Chapter 2.
Java Basics Data Types in Java.
Presentation transcript:

The C# language fundamentals ( I ) P.F. Tsai

Hello World Project Please follow the instructions mentioned in the previous class to build a hello world project

Types C# is a strong typed language Weak Type: a value of one type is a bit-pattern which can be re- interpreted as a value of another type (C) Strong Type: a cast always involves a compile-time or run-time compatibility check, and a meaningful conversion. (JAVA & C#) Two sets of Types Intrinsic (built-in) types User-defined types Value types vs Reference types Stack vs Managed heap Declaration

Stack and Heap Stack The stack data structure First In Last Out Memory An area of memory supported by CPU and used to store local variables Pointed by the SP register Referred by the variable names Heap An area of memory managed by VM Garbage collector (GC)

Value types vs Reference types All intrinsic types are value types except for Object and String All user-defined types are reference types except for structs Examples: int myAge = 33; Variable contains the value string myName = “ Mandy ” ; Variable contains the address of the value

Intrinsic types (primitives)

Types frequently used bool True and false short, int & long Depends on your need Ram is CHEAP but time is EXPENSIVE Double, float(f) & decimal(m) Double is default float somefloat = 57f;

Types frequently used The char type represents a Unicode Unicode provides a unique number for every character no matter what the platform, program & language are chinese.html Example: char myChar = ‘ A ’ ; // ‘ \u0041 ’ use single quote  ‘ ‘ Escape characters For special purposes

Escape characters

Exercise 1 Please try to print the following message “ Hello World! ” (and BEEP!) trick: Console.Read();

Exercise 2 Please try to store your personal data into variables with corresponding types your name, age, gender, marriage, phone number, height, weight, birthday & your home address Ex: string name = “ Mandy Tsai ” ; // use double quote

Converting intrinsic types Objects of one type can possibly be converted into another type Implicit cast Explicit cast Example short x = 5; int y = x; //implicit int x = 5; short y = (short) x; // explicit

Exercise 3 Please try to figure out the value range of a short type variable and modify the above example (the explicit one) with assigning x a value outside the short- type range to see what happens then.

WriteLine() A formatted output Console.WriteLine( “ I am {0} years old and she is {1} years old “, myAge, herAge); An easier way Console.WriteLine( “ I am “ +myAge+ ” years old and she is “ +herAge+ ” years old ” );

More about WriteLine()

Exercise 4 Now you can modify your exercise 2 to show your personal information on the screen Example Name : Mandy Tsai Age : 33 Gender: Male …

Variables and Constants Initializing and assigning a value to a variable identifier case 1, 2 & 3

Identifer Names of your types, variables, methods, constants, objects and so forth Naming convection Camel notation for variables myVariable Pascal notation for methods and others MyFunctionName No clash with keywords

Case 1

Case 2

Case 3

Variables and Constants Constants A constant is a variable whose value can not be changed Memorizing names is much easier than numbers

Example

Exercise 5 Please try to implement the above example and modify the constant value to see what happens. FreezingPoint = FreezingPoint + 1; System.Console.WriteLine("Freezing point of water: {0}", FreezingPoint );

Enumerations An alternative to constants Value type A set of named constants (enumerator list) Restricted to integer types except for char

Examples Declare an enumeration define the type of constants

Example codes Access the constant by a dot operator Example 3-5 in the textbook (buggy) Declared outside Main() (int)

Special case

Conditional branching statements A conditional branch is created by a conditional statement, which is signaled by keywords such as if, else, or switch A conditional branch occurs only if the condition expression evaluates true Only boolean values are accepted here

If - else Unlike Matlab, it doesn ’ t need end Can be nested The code block use { } to mark the statement

Example codes

Operators will discussed later

Exercise 6 You need to write a program to evaluate the temperature of a batch tank, and specifically to return the following types of information: If the temperature is 50 degrees or lower, the program should warn you about temperature is way too low. If the temperature is between 50 to 70 degrees, the program should tell you that the process is under control. If the temperature is 70 degrees or higher, the program should warn you about temperature is way too high.

References C# programming 清華大學金仲達教授課程教材 嵌入式軟體聯盟 (Embedded Software Consortium)