Introduction To C#.NET

Similar documents
Introduce C# as Object Oriented programming language. Explain, tokens,

Introduction to Programming Using Java (98-388)

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

Introduction to C# Applications

And Even More and More C++ Fundamentals of Computer Science

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

Chapter-8 DATA TYPES. Introduction. Variable:

Chapter 1 Getting Started

7. C++ Class and Object

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations

Question And Answer.

C++ (Non for C Programmer) (BT307) 40 Hours

C# Fundamentals. Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh

Object Oriented Programming with Visual Basic.Net

Short Notes of CS201

CS201 Some Important Definitions

CS201 - Introduction to Programming Glossary By

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings

Object-Oriented Programming

VARIABLES AND TYPES CITS1001

CSE 12 Week Eight, Lecture One

Lecture 18 Tao Wang 1

Visual C# Instructor s Manual Table of Contents

.Net Technologies. Components of.net Framework

C# MOCK TEST C# MOCK TEST I

C++ C and C++ C++ fundamental types. C++ enumeration. To quote Bjarne Stroustrup: 5. Overloading Namespaces Classes

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

PROGRAMMING FUNDAMENTALS

C#: framework overview and in-the-small features

Assumptions. History

Programming in C and C++

Getting started 7. Storing values 21. Creating variables 22 Reading input 24 Employing arrays 26 Casting data types 28 Fixing constants 30 Summary 32

DC69 C# &.NET DEC 2015

Input And Output of C++

CS 231 Data Structures and Algorithms, Fall 2016

Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators,

Preview from Notesale.co.uk Page 6 of 52


data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

DigiPen Institute of Technology

DAD Lab. 1 Introduc7on to C#

inside: THE MAGAZINE OF USENIX & SAGE August 2003 volume 28 number 4 PROGRAMMING McCluskey: Working with C# Classes

Your first C++ program

C# INTRODUCTION. Object. Car. data. red. moves. action C# PROGRAMMERS GUIDE LESSON 1. CsGuideL1.doc. Date Started: May 8,2001

EEE-425 Programming Languages (2013) 1

Object Oriented Software Design II

IT150/IT152 Concepts Summary Sheet

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

Program Organization and Comments

C++\CLI. Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

CSc Introduction to Computing

Lab # 02. Basic Elements of C++ _ Part1

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.

CS201 Latest Solved MCQs

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

Variables. Data Types.

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

EEE-425 Programming Languages (2013) 1

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

BTE2313. Chapter 2: Introduction to C++ Programming

G52CPP C++ Programming Lecture 13

A Comparison of Visual Basic.NET and C#

Chapter 10 Introduction to Classes

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

Java Bytecode (binary file)

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

IT 374 C# and Applications/ IT695 C# Data Structures

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Introduction to C++ with content from

Data Types and Variables in C language

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

Sri Vidya College of Engineering & Technology

Chapter 2: Using Data

BASIC ELEMENTS OF A COMPUTER PROGRAM

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

Syntax and Variables

PES INSTITUTE OF TECHNOLOGY

EL2310 Scientific Programming

An Introduction to C++

Introduction to Java

Introduction to C++ Systems Programming

CSE 303: Concepts and Tools for Software Development

Scientific Computing

Very similar to Java C++ C-Based syntax (if, while, ) object base class no pointers, object parameters are references All code in classes

C # Language Specification

OBJECT ORIENTED PROGRAMMING

Absolute C++ Walter Savitch

Array. Array Declaration:

EEE-425 Programming Languages (2013) 1

C# Types. Industrial Programming. Value Types. Signed and Unsigned. Lecture 3: C# Fundamentals

Memory and C++ Pointers

Static Members. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

C++ 8. Constructors and Destructors

Transcription:

Introduction To C#.NET Microsoft.Net was formerly known as Next Generation Windows Services(NGWS).It is a completely new platform for developing the next generation of windows/web applications. However this new platform required a language which would take its full advantage; this is one of the factors that led to the development of C#. C# has evolved from C/C++. The #(hash symbol ) in musical notations is used to refer to a sharp note and is called Sharp, hence the name is pronounced as C Sharp The C# compiler is considered to be the most efficient compiler in the.net family and a major part of the.net base class libraries itself are written in C#. Moreover, C# could be considered as a modern replacement for C/C++ 1

It is important to look at C# not just a programming language but as an integral part of the.net platform. Another important feature of C# is that it is a real object oriented programming language. This may not sound very exciting since we do have powerful programming languages like C++, and C# has its root in C++. The key point of C# however is that it enhances developer productivity and increases safety by enforcing strict type checking. It features a garbage collector, which relieves the programmer of the burden of manual memory management. C# offers extensive interoperability. 2

Program Flow Of C# To understand the flow of C# program, let us begin analyzing a very simple program in C# which simply displays a message on the users screen. 1: /* This is a simple program in C# */ 2: using System; 3: class First 4: { 5: public static void Main() 6: { 7: Console.WriteLine ( My First C# Program ); 8: } 9: } 3

Line 1: This is a comment in C#. Comments can be included in any part of C# program. The comment begins with /* and ends with */. The comment can span multiple lines. Line 2: This line using System is quite similar to the # include statement used in C/C++. The System namespace contains the classes that most applications used for interacting with the operating system. (Namespaces are nothing but a collection of classes). The classes that are used more often are the ones required for basic input/output. Note that there is a semicolon at the end of this line. All lines of code in C# must end with a semicolon just like C/C++. Line 3: This line defines a class Line 4: This line defines a open curly braces for a class Line 5: Each class has one static void Main() function. This function is the entry point of a C# program. Line 6: Next we open the scope of the method or function using curly braces 4

Line 7:Within the Main() function we call the WriteLine method of the Console class and pass the text My First C# program as its parameter. The WriteLine function displays text on the console. The WriteLine method is a part of the Console class, which in turn is a part of the System namespace. Line 8: The Main() function is terminated using the closing braces. Line 9: The class is terminated using the closing braces. Note: C# is case sensitive For Example: the keyword using is not the same as Using 5

Basic C# Programming Concepts Declaring Variables In C# Basic Input/Output in C# Selection Statements in C# Iteration Constructs in C# Constructors in C# Destructors in C# Fundamentals Types of C# Data Types In C# Arrays in C# Structs in C# Enumerators In C# 6

Declaring Variables In C# Variables in C# are declared in the following way: AccessModifier DataType VariableName; Ex: public String MyVar; Access Modifier Public Protected Private Description Makes a member accessible from anywhere Makes a member accessible within the class and all classes derived from it Makes a member accessible only within a class 7

The DataType could be any of the variable types in C#. A few of the valid intrinsic C# datatypes are listed below C# Data Types Description Int String Declares a variable which stores integer values. It takes upto 4 bytes of memory Declares a variable which stores string values Float Declares a variable which stores integer values with decimals 8

The DataType could also be an array definition or a custom data type like enumerators or even a class name for creating an object. The variable name should be a valid C# variable name. The rules for naming variables in C# are just the same as in C. In almost all programming languages, keywords are not allowed to be used as identifiers. However, C# has work around on this issue. You can use variables which clash with the keywords by prefixing the identifier with an @symbol Example: You can declare a variable like @int using keyword int as a variable name. 9

Basic Input/Output in C#: Basic input and output operations are performed in C# using the methods of Console class in the System namespace. The two methods used are Console.WriteLine() Console.ReadLIne() Console.WriteLine() method is used for displaying text on the user screen. It can be used to format text before displaying it. It takes upto four additional parameters, which are known as the format string specifiers. The format string specifiers specify how data will be displayed and it can also serve as a placeholders, which determine where the values of the specified variable will be displayed in the string. Console.ReadLine() method is used to get the input from the user which reads all characters upto a carriage return and returned it back as a string. 10

Selection Statements In C#: The selection statements are used to perform operations based on the value of an expression as we have done in C programming. Types of selection statements used: If Condition If-Else Condition Switch Case Construct Iteration Constructs In C#: The iteration or looping statements are used to perform certain set of instructions a certain number of times or while a specific condition is true. Types of iteration/looping constructs used: The for loop The while loop The do loop The foreach loop Except foreach loop all others are very similar to the ones in C. 11

Constructors In C#: As we already know constructors are special methods which has the same name as the class name as in case of C++, Java. Destructors In C#: Destructors in C# are written in the same way as constructors are written. It has the same name as the class except there is a ~(tilde) symbol prefixed to it. Syntax Of Constructors/Destructors In C#: using System; Class MyClass { } public MyClass() { //My Class Constructor } public ~MyClass() { // My Class Destructor } 12

Fundamental Types Of C#: C # divides data types into two fundamental categoriesvalue types and reference types. Most of the basic data types in C# for example (int, char) are value types. Structures are also value types. Reference types includes classes, interfaces, arrays and strings. A value type represents the actual data stored on the stack, whereas reference type represents a pointer or reference to the data and are stored on the heap. The basic difference between the two is in the way they are stored on the memory. Boxing and Unboxing- Boxing in simple terms is nothing but conversion of a value type into a reference type. Similarly, unboxing is all about converting a reference type into a value type. 13

Data Types In C#: C# provides us with an Unified Type System. This means that all the data types in C#, be it a reference type or value type are derived from just one class, the object class which means that the object class is the ultimate base class for all data types. Arrays In C#: Arrays are group of values of similar data type. These values are stored in contiguous memory locations, thereby,making it easier to access and manipulate values. Arrays in C# belong to the reference type and hence are stored on heap. Array declaration in C#- DataType [number of elements] variablename; For Exampleint [5] myarr; 14

Structs In C#: Unlike the structs of C/C++, the structures in C# can have methods defined within them and they can have a constructor too. Enumerators In C#: Enums short for Enumerators are a set of named numeric constants which are useful when some value in a program can have a specific set of values. 15