C#C# Introduction CS3260 Dennis A. Fairclough Version 1.0 Introduction CS3260 Dennis A. Fairclough Version 1.0.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
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.
Programming Languages and Paradigms The C Programming Language.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 6 th Lecture Pavel Ježek
C# Language Report By Trevor Adams. Language History Developed by Microsoft Developed by Microsoft Principal Software Architect Principal Software Architect.
Lab#1 (14/3/1431h) Introduction To java programming cs425
C#: Data Types Based on slides by Joe Hummel. 2 UCN Technology: Computer Science Content: “.NET is designed around the CTS, or Common Type System.
BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#. 
The Type System1. 2.NET Type System The type system is the part of the CLR that defines all the types that programmers can use, and allows developers.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
C# Structs, operator overloading & attributes. Structs ~ Structures Structs are similar to classes: they represent data structures with data and functions.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow 
C#: Project Cool Arthur Ketchel II Keith Francisco Chris McInnis.
3. Data Types. 2 Microsoft Objectives “.NET is designed around the CTS, or Common Type System. The CTS is what allows assemblies, written in different.
Lecture 9 Concepts of Programming Languages
Peter Juszczyk CS 492/493 - ISGS. // Is this C# or Java? class TestApp { static void Main() { int counter = 0; counter++; } } The answer is C# - In C#
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
From C++ to C#. Web programming The course is on web programming using ASP.Net and C# The course is on web programming using ASP.Net and C# ASP.Net is.
Programming in C# Language Overview
Programming Principles Data types and Variables. Data types Variables are nothing but reserved memory locations to store values. This means that when.
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
1. 2 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Decisions { class.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
.NET Framework Introduction: Metadata
C#C# Classes & Methods CS3260 Dennis A. Fairclough Version 1.1 Classes & Methods CS3260 Dennis A. Fairclough Version 1.1.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
Introduction to C# C# is - elegant, type-safe, object oriented language enabling to build applications that run on the.NET framework - types of applications.
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.
Keith Elder Microsoft MVP
C# Versus Java Author: Eaddy, Marc Source: Software Tools for the Professional Programmer. Dr. Dobb's Journal. Feb2001, Vol. 26 Issue 2, p74 Hong Lu CS699A.
C# Language Panithan Chandrapatya Agenda C# History C# Goals C# Fixes C# Contribution C# Features C# Success C# Example.
Universidad Nacional de Colombia Facultad de Ingeniería Departamento de Sistemas ertificación en AVA.
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
Types in programming languages1 What are types, and why do we need them?
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?
Bill Campbell, UMB Microsoft's.NET C# and The Common Language Runtime.
Chapters 2 & 3. .NET Software development model that allows applications created in disparate programming languages to communicate Universal data access.
Advanced Programming C# Introduction.
Attributes C#.Net Software Development Version 1.0.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 8 th Lecture Pavel Ježek
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Object Oriented Software Development 4. C# data types, objects and references.
1.2 Primitive Data Types and Variables
Introduction to C# By: Abir Ghattas Michel Barakat.
INTRODUCTION CHAPTER #1 Visual Basic.NET. VB.Net General features It is an object oriented language  In the past VB had objects but focus was not placed.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Introduction to C# Anders Hejlsberg Distinguished Engineer Developer Division Microsoft Corporation.
Overview CNS 3260 C#.NET Software Development. 2.NET Framework Began in 2000 Developed in three years (2000 to 2003) Operating System Hardware.NET Framework.
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
Java Programming Language Lecture27- An Introduction.
Value Types. 2 Objectives Discuss concept of value types –efficiency –memory management –value semantics –boxing –unboxing –simple types Introduce struct.
INTRODUCTION BEGINNING C#. C# AND THE.NET RUNTIME AND LIBRARIES The C# compiler compiles and convert C# programs. NET Common Language Runtime (CLR) executes.
C++ Lesson 1.
Basic Introduction to C#
Java Primer 1: Types, Classes and Operators
Understand Computer Storage and Data Types
CS360 Windows Programming
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
Programming in C# CHAPTER 1
Dr Shahriar Bijani Winter 2017
Chapter 3 Introduction to Classes, Objects Methods and Strings
Data Types Imran Rashid CTO at ManiWeber Technologies.
.NET Base Type (CTS Data Type) Managed Extensions for C++ Keyword
Chapter 3 Introduction to Classes, Objects Methods and Strings
Presentation transcript:

C#C# Introduction CS3260 Dennis A. Fairclough Version 1.0 Introduction CS3260 Dennis A. Fairclough Version 1.0

Introduction C# (pronounced “See Sharp”) is a simple, modern, object-oriented, and type-safe programming language. C# has its roots in the C family of languages and will be immediately familiar to C, C++, and Java programmers. C# is standardized by ECMA International as the ECMA-334 standard and by ISO/IEC as the ISO/IEC standard. Microsoft’s C# compiler for the.NET Framework is a conforming implementation of both of these standards. Standard Copyright © 2010 by Dennis A. Fairclough all rights reserved.

C# Simple Object-Oriented Type Safe Rooted – C, C++ ECMA/ISO - Standards Simple Object-Oriented Type Safe Rooted – C, C++ ECMA/ISO - Standards 3 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

Components C# is an object-oriented language, but C# further includes support for component-oriented programming. Contemporary software design increasingly relies on software components in the form of self-contained and self-describing packages of functionality. Key to such components is that they present a programming model with properties, methods, and events; they have attributes that provide declarative information about the component; and they incorporate their own documentation. 4 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

Components Self-Contained Self-Describing Packages of Functionality Self-Contained Self-Describing Packages of Functionality 5 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

Packages of Functionality Variables/Fields - private Properties/Indexers - public –Variables/Fields via get/set methods Methods – public –Behaviors/Functions Events –Messages/Program Events Attributes –Metadata Variables/Fields - private Properties/Indexers - public –Variables/Fields via get/set methods Methods – public –Behaviors/Functions Events –Messages/Program Events Attributes –Metadata 6 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

C# Features Several C# features aid in the construction of robust and durable applications: Garbage Collection (gc) automatically reclaims memory occupied by unused objects; Exception Handling provides a structured and extensible approach to error detection and recovery; and the Type-Safe design of the language makes it impossible to read from uninitialized variables, to index arrays beyond their bounds, or to perform unchecked type casts. 7 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

C# Features Garbage Collection –Memory Management/Reclaim Exception Handling –Robust Error Handling Type-Safe –Uninitialized Variables/Index Bounds/Casts Garbage Collection –Memory Management/Reclaim Exception Handling –Robust Error Handling Type-Safe –Uninitialized Variables/Index Bounds/Casts 8 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

Unified Type System C# has a Unified Type System. All C# types, including primitive types such as int and double, inherit from a single root object type. Thus, all types share a set of common operations, and values of any type can be stored, transported, and operated upon in a consistent manner. Furthermore, C# supports both user-defined reference types and value types, allowing dynamic allocation of objects as well as in-line storage of lightweight structures. 9 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

10

Unified Type System Every datatype is an object! Rooted in Object – Single Inheritance Share – Operations/Values Value Types – Lightweight Objects –int, double, char, decimal, struct Reference Types – Reference/Object pair –DATA dobj = new DATA(); Every datatype is an object! Rooted in Object – Single Inheritance Share – Operations/Values Value Types – Lightweight Objects –int, double, char, decimal, struct Reference Types – Reference/Object pair –DATA dobj = new DATA(); 11 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

Program Structure static class Hello//containing class/object { static void Main() //program entry point method { System.Console.WriteLine("Hello, World"); } static class Hello//containing class/object { static void Main() //program entry point method { System.Console.WriteLine("Hello, World"); } 12 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

Did you register your Clicker? Copyright © 2010 by Dennis A. Fairclough all rights reserved True 2.False 1.True 2.False

Files Files have.cs file extension csc hello.cs //c# compiler -.Net Framework hello.exe //MSIL file hello.exe -> CLR for execution –(Common Language Runtime) Files have.cs file extension csc hello.cs //c# compiler -.Net Framework hello.exe //MSIL file hello.exe -> CLR for execution –(Common Language Runtime) 14 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

Program Structure The key organizational concepts in C# are programs, namespaces, types, members, and assemblies. C# programs consist of one or more source files. Programs declare types, which contain members and can be organized into namespaces. Classes and interfaces are examples of types. Fields, methods, properties, and events are examples of members. When C# programs are compiled, they are physically packaged into assemblies. Assemblies typically have the file extension.exe or.dll, depending on whether they implement applications or libraries. 15 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

Programs One or more source files –.cs extension NO.h files ! Contain one or more Classes static void Main() – Entry Point Method Body Declare Types –int x = 0; One or more source files –.cs extension NO.h files ! Contain one or more Classes static void Main() – Entry Point Method Body Declare Types –int x = 0; 16 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

Types Types – Classes, Interfaces Organized into Namespaces Contain Members –Fields –Methods –Properties –Events Types – Classes, Interfaces Organized into Namespaces Contain Members –Fields –Methods –Properties –Events 17 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

Assemblies Complied Programs –.exe//Applications –.dll//Libraries Complied Programs –.exe//Applications –.dll//Libraries 18 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

Multi-file Program C# permits the source text of a program to be stored in several source files. When a multi-file C# program is compiled, all of the source files are processed together, and the source files can freely reference each other—conceptually, it is as if all the source files were concatenated into one large file before being processed. Forward declarations are never needed in C# because, with very few exceptions, declaration order is insignificant as C# is a multipass compiler. C# does not limit a source file to declaring only one public type nor does it require the name of the source file to match a type declared in the source file. 19 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

Multipass Compiler Eliminates the need of “order” in source files. 20 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

C# Types There are two kinds of types in C#: value types and reference types. Variables of value types directly contain their data where as variables of reference types store references to their data, the latter being known as objects. With reference types, it is possible for two variables to reference the same object and thus possible for operations on one variable to affect the object referenced by the other variable. With value types, the variables each have their own copy of the data, and it is not possible for operations on one to affect the other (except in the case of ref and out parameter variables). 21 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

C# Types Value Types –Lightweight Objects –Single Objects Reference Types –Objects Reference Value Pair Value Types –Lightweight Objects –Single Objects Reference Types –Objects Reference Value Pair 22 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

Value Types C#’s Value Types are further divided into –simple types –enum types –struct types –nullable types C#’s Value Types are further divided into –simple types –enum types –struct types –nullable types 23 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

Reference Types C#’s Reference Types are further divided into –class types –interface types –array types –delegate types. C#’s Reference Types are further divided into –class types –interface types –array types –delegate types. 24 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

CategoryDescription Value types Simple typesSigned integral: sbyte, short, int, long Unsigned integral: byte, ushort, uint, ulong Unicode characters: char IEEE floating point: float, double High-precision decimal: decimal Boolean: bool Enum typesUser-defined types of the form enum E {...} Struct typesUser-defined types of the form struct S {...} Nullable typesExtensions of all other value types with a null value Reference types Class typesUltimate base class of all other types: object Unicode strings: string User-defined types of the form class C {...} Interface typesUser-defined types of the form interface I {...} Array typesSingle- and multi-dimensional, for example, int[] and int[,] Delegate typesUser-defined types of the form e.g. delegate int D(...) 25 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

CategoryBitsTypeRange/Precision Signed integral 8 sbyte – short –32, , int –2,147,483, ,147,483, long –9,223,372,036,854,775, ,223,372,036,854,775,807 Unsigned integral 8 byte ushort , uint 0...4,294,967, ulong ,446,744,073,709,551,615 Floating point 32 float 1.5 × 10 −45 to 3.4 × 10 38, 7-digit precision 64 double 5.0 × 10 −324 to 1.7 × , 15-digit precision Decimal128 decimal 1.0 × 10 −28 to 7.9 × 10 28, 28-digit precision 26 Copyright © 2010 by Dennis A. Fairclough all rights reserved.

Simple Types Copyright © 2010 by Dennis A. Fairclough all rights reserved. 27 Reserved wordAliased type sbyteSystem.SByte byteSystem.Byte shortSystem.Int16 ushortSystem.UInt16 intSystem.Int32 uintSystem.UInt32 longSystem.Int64 ulongSystem.UInt64 charSystem.Char floatSystem.Single doubleSystem.Double boolSystem.Boolean decimalSystem.Decimal

Comments // … single line /* … multiline … */ /// … XML documentation // … single line /* … multiline … */ /// … XML documentation Copyright © 2010 by Dennis A. Fairclough all rights reserved. 28

Example Program Copyright © 2010 by Dennis A. Fairclough all rights reserved. 29