Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.

Slides:



Advertisements
Similar presentations
Object Oriented Programming in JAVA
Advertisements

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.
Data Types and Expressions
Types and Variables. Computer Programming 2 C++ in one page!
Structure of a C program
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Data types and variables
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Chapter 2 Data Types, Declarations, and Displays
Chapter 2: Introduction to C++.
JavaScript, Third Edition
Data Types.
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.
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.
L EC. 02: D ATA T YPES AND O PERATORS (1/2) Fall Java Programming.
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.
CS2311 Computer Programming Dr. Yang, Qingxiong (with slides borrowed from Dr. Xu, Henry) Lecture 2: Basic Syntax – Part I: Variables and Constants.
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
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.
CPS120: Introduction to Computer Science Variables and Constants Lecture 8 - B.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
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.
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.
Chapter 2: Using Data.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
CPS120: Introduction to Computer Science
Lecture #5 Introduction to C++
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Chapter 2: Java Fundamentals
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Characters and tokens Characters are the basic building blocks in C program, equivalent to ‘letters’ in English language Includes every printable character.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
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,
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
Copyright Curt Hill Variables What are they? Why do we need them?
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
1.2 Primitive Data Types and Variables
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 1)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Numbers in ‘C’ Two general categories: Integers Floats
Definition of the Programming Language CPRL
BASIC ELEMENTS OF A COMPUTER PROGRAM
Computing with C# and the .NET Framework
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
2.1 Parts of a C++ Program.
Basics of ‘C’.
C++ Data Types Data Type
Chapter 2: Introduction to C++.
WEEK-2.
Lexical Elements & Operators
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables and Constants
Programming Fundamental-1
Presentation transcript:

Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five types of tokens Identifiers Keywords Literals Operators Punctuators

Identifiers That are programmer designed tokens (like variable name) They are used to naming classes, methods, variables, labels, namespaces etc.. Rules for Identifiers are as follows:- They can have alphabets, digits and underscore characters They must not begins with digit Uppercase and lowercase letters are distinct Keywords in standalone can not be use as identifier

Keywords That are the reserved words, and whose meaning is already explained to the C# compiler They can not be used as identifiers except when they are prefaced character Some Examples of keywords are AbstractEventNamesp ace StaticAsExplicitNew StringBaseExternNullStructBoolFalse ObjectSwitchFinallyOperatorThisByteChar ForeachIfElseContinueDoEnumLong

Literals Literals are the way in which values that are stored in variables are represented So it is the value constants assigned to variables, or it is a result of expression in program C# Literals Numeric Booleancharacter String Single character Realinteger

Integer literals That is sequence of digit There are two type of integer Decimal (digit between 0 to 9 with optional minus sign) Hexadecimal (sequence preceded by 0x ) Spaces, commas and non-digit characters are not permitted between digits

Real Literals Number contains fractional part like are called real or floating point numbers Example of valid real literals are Real literals also may expressed in exponential Mantissa e exponent 0.65e4

Boolean literals There are two Boolean literals values True False They are used as a values of relational expression

Characters Literals Single character literals That is a literal which contain single character enclosed within a pair of single quote marks. Eg: ‘2’, ‘a’, ‘ ’ String Literals: That contains sequence of characters Eg: “hi hello”, “02023u”

Backslash character Literals Some special constants that are used in output methods Constantmeaning ‘\a’Alert ‘\b’Back space ‘\n’New line ‘\r’Carriage return ‘\t’Horizontal tab ‘\v’Vertical tab ‘\’’Single Quote ‘\’”’Double Quote ‘\\’Backslash ‘\0’Null

Variable A variable is an identifier that is used to give name of storage location Constant remain unchanged during the program execution, A variable can change value during program execution Variable name can be chosen by programmer in a meaningful way, so as to reflect what it represent in program Variable name can be of any length

Data Type It specifies size and type of values can be stored Data types are divide in two categories: Value type Reference type These two types differ to each other by Where they are stored in memory How they behave in context of assignment statement Value type stored on stack, and when a value of variable assigned to another variable it actually copies the value, so two identical copies of the value are available in memory Reference type stored on heap of memory, when an assignment between two reference variable occurs, it copies only reference, actual value remains in same memory location

Type System Value types (user defined) Enums enum State { Off, On } Structs struct Point { int x, y; } Reference types (use defined) Classes class Foo: Bar, IFoo {...} Interfaces interface IFoo: IBar {...} Arrays string[] a = new string[10]; Delegates delegate void Empty();

Predefined Types C# predefined types Reference object, string Signed sbyte, short, int, long Unsigned byte, ushort, uint, ulong Character char Floating-point float, double, decimal Logical bool

nullable Type C# added a new type called nullable type This type variable can hold undefined value Any value type variable can be defined as a nullable type

Declaration and initialization of variable Declaration : int al float b; double pi; byte b; char c1,c2,c3; decimal d1,d2; uint m; ulong n; Variable name = Value; or Type variable name = value; or X=y=z=0;

Default Values TypeDefault Value All integer type0 Char type‘\x000’ Flaot type0.0f Double type0.0d Decimal type0.0 m Bool typeFalse Enum type0 All reference typenull

CONSTANT variable The variable whose value do not change during execution of program is known as constant variable const int a=10; Remember const int a; a=10; is illegal We do not use non constant value in expression int m=10; Const int n=m*5; //cause an error

Scope of Variables Scope mean is a region of code within which variable can be accessed C# defined several categories of variables Static Instance Array element Value parameters Output Parameters Local Variables

Class ABC { static int m; int n; void fun(int x,ref int y,out int z,int[] a) { int j=10; ………. } Static Variable Instance Variable X= Value Parameter Y = Reference Parameter Z= Output parameter a[0] = array element

Static and instance variable are known as field variable and scope begins at the place of declaration and ends when Main method terminates The variable x,y,z are parameters of method fun() X will exist till the end of the method Y and z do not create new storage location, instead, they represent the same storage location as the variable that are passed as argument The scope of variable is always same as underlying variable Array instance a[0] come in existence when an array instance is created, and exit when there are no references to that array instance Local variable can be used within that method only

BOXING and UNBOXING In OOP, methods are invoked using object Since int a, where a is a variable, can not be used to call method like a.fun() For that we need to convert that value type to Object So boxing mean conversion of a value type on stack to a object type on a heap Conversion of object type back to value type is known as unboxing

BOXING int m=100; Object obj=m; // create a box to hold m (BOXING) int m=10; object obj = m; m=20; Console.WriteLine(m); Console.WriteLine(obj);

UNBOXING int m=10; Object ob=m; //box m int n = (int)obj; //unboxing