2. C# Language Fundamentals

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Advertisements

Procedural Programming in C# Chapters Objectives You will be able to: Describe the most important data types available in C#. Read numeric values.
Execute Blocks of Code Multiple Times Svetlin Nakov Telerik Corporation
Today’s lecture Review of Chapter 1 Go over homework exercises for chapter 1.
Execute Blocks of Code Multiple Times Telerik Software Academy C# Fundamentals – Part 1.
C# Language Report By Trevor Adams. Language History Developed by Microsoft Developed by Microsoft Principal Software Architect Principal Software Architect.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Neal Stublen C# Data Types Built-in Types  Integer Types byte, sbyte, short, ushort, int, uint, long, ulong  Floating Point Types.
Data Types and Expressions
Types and Variables. Computer Programming 2 C++ in one page!
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common.
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.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
COMPUTER PROGRAMMING. Data Types “Hello world” program Does it do a useful work? Writing several lines of code. Compiling the program. Executing the program.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
Input & Output: Console
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
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.
Chapter 2: Using Data.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
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.
M.T.Stanhope Oct Title : C++ Basics Bolton Institute - Faculty of Technology (Engineering) 1 C++ Basics u Data types. u Variables and Constants.
Fundamental Programming: Fundamental Programming Introduction to C++
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
CHAPTER 2 C++ SYNTAX & SEMANTICS #include using namespace std; int main() { cout
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
1.2 Primitive Data Types and Variables
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Objects Variables and Constants. Our Scuba Problem #include // cin, cout, > using namespace std; int main() { const double FEET_PER_ATM = 33.0, LBS_PER_SQ_IN_PER_ATM.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Computer Programs CS 1400 Dennis A. Fairclough Version 1.1 CS 1400 Dennis A. Fairclough Version 1.1.
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 C#. 2 C#’s Family Tree C# inherits a rich programming legacy from C (1972) and C++ (1979). It is closely related to Java (1991).
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
C++ Lesson 1.
Chapter 1.2 Introduction to C++ Programming
Basic Introduction to C#
Chapter 2: Basic Elements of C++
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
C# — Console Application
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Lecture 2 Data Types Richard Gesick.
Computing Fundamentals
Basic Elements of C++.
Introduction to C++ October 2, 2017.
Computing with C# and the .NET Framework
Chapter 3: Understanding C# Language Fundamentals
Basic Elements of C++ Chapter 2.
.Net Programming with C#
Variables, Loops, Decision Statements, etc
Module 2: Understanding C# Language Fundamentals
Govt. Polytechnic,Dhangar
C++ Programming Lecture 3 C++ Basics – Part I
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Variables and Constants
Presentation transcript:

2. C# Language Fundamentals Data Types Numeric Types Non-Numeric Types: char and bool Variables Definite Assignment Constants Strings Statements Code Samples

Data Types Common C# intrinsic data types Type Size in Bytes byte 1 bool 2 int 4 long 8 float double decimal 12

Typing in C# C# is a strongly typed language Types come in two flavours Value (intrinsic) Reference (classes …) Each type has a name (int) and size (4b) The .Net equivalents for int is Int32

Numeric Data Types Unsigned (positive) Signed (positive or negative) byte, ushort, uint, ulong Signed (positive or negative) short, int, long, float, decimal, double Select the smallest type that will hold the required range of numbers

Non-Numeric Types: char and bool Holds just a single character Can hold: Simple character (‘A’) Unicode character (u\0041) Escape character (‘\n’) bool Holds true or false in one byte

Declaring Local Variables int myInt; System.Console.WriteLine("Uninitialized, myInt: {0}",myInt); myInt = 5; int mySecondInt = 10; // declare and initialise int myInt4,myInt5; // declare multiple variables What is the value on an integer before it is initialised?

Declaring Constants Why would you create constants? const int FreezingPoint = 32; // degrees Farenheit const int BoilingPoint = 212; Why would you create constants?

Declaring Enumerations An enumeration is a set of named constants // declare the enumeration enum Temperatures:int { WickedCold = 0, FreezingPoint = 32, LightJacketWeather = 60, SwimmingWeather = 72, BoilingPoint = 212, } The data type defaults to int Why would you create enumerations?

Using Enumerations System.Console.WriteLine("Freezing point of water: {0}", (int) Temperatures.FreezingPoint ); System.Console.WriteLine("Boiling point of water: {0}", (int) Temperatures.BoilingPoint );

Declaring Strings A string is an object string myString = “Hello World” ;// declare and initialise string Where would you use strings in your code?

Statements, Expressions & White Space A statement ends in a semicolon int myInt = 23; An expression can be part of an assignment myInt = myInt * 23; White spaces are ignored myInt = myInt * 100;

Unit 2 Lab To write statements that prompt and greet the user 1. Open Visual Studio.Net and create a new C# Console Application project 2. In the Main method insert the following line: string myName; 3. Write a statement that prompts users for their name. 4. Write another statement that reads the user’s response from the keyboard and assigns it to the myName string. 5. Add one more statement that prints “Hello myName” to the screen (where myName is the name the user typed in). 6. Save your work.

Unit 2 Lab … When completed, the Main method should contain the following: static void Main( ) { string myName; Console.WriteLine("Please enter your name"); myName = Console.ReadLine( ); Console.WriteLine("Hello {0}", myName); }