Language Fundamentals in brief C# - Introduction.

Slides:



Advertisements
Similar presentations
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 12 th -13 th Lecture Pavel Ježek.
Advertisements

Topic 10 Java Memory Management. 1-2 Memory Allocation in Java When a program is being executed, separate areas of memory are allocated for each class.
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.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
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++
C#/.NET Jacob Lewallen. C# vs.NET.NET is a platform. Many languages compile to.NET: –VB.NET –Python.NET –Managed C++ –C#
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.
Reference Types. 2 Objectives Introduce reference types –class –array Discuss details of use –declaration –allocation –assignment –null –parameter –aggregation.
Lecture 9 Concepts of Programming Languages
4. Statements and Methods. 2 Microsoft Objectives “With regards to programming statements and methods, C# offers what you would come to expect from a.
Abstract Data Types and Encapsulation Concepts
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
OOP Languages: Java vs C++
11 Values and References Chapter Objectives You will be able to: Describe and compare value types and reference types. Write programs that use variables.
JavaServer Pages Syntax Harry Richard Erwin, PhD CSE301/CIT304.
C#: Statements and Methods Based on slides by Joe Hummel.
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
Windows Programming Using C# Classes & Interfaces.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Classes and Objects. Topics The Class Definition Declaring Instance Member Variables Writing Instance Member Methods Creating Objects Sending Messages.
FEN 2012 UCN Technology: Computer Science1 C# - Introduction Language Fundamentals in Brief.
C# Programming Fundamentals of Object-Oriented Programming Fundamentals of Object-Oriented Programming Introducing Microsoft.NET Introducing Microsoft.NET.
Spring 2007NOEA: Computer Science Programme 1 C# - Introduction Language Fundamentals: Data Types string Objects and Classes Methods Iteration and Selection.
C# Intro Programming languages and programs: Source code and object code Editors and compilers C# fundamentals: Program structure Classes and Objects Variables.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Constructors CMSC 202. Object Creation Objects are created by using the operator new in statements such as… The following expression invokes a special.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
Advanced Java Programming CS 537 – Data Structures and Algorithms.
C# EMILEE KING. HISTORY OF C# In the late 1990’s Microsoft recognized the need to be able to develop applications that can run on multiple operating system.
Generic Programming  Object Type  Autoboxing  Bag of Objects  JCL Collections  Nodes of Objects  Iterators.
1 Enumerations and Structs Chapter 9. 2 Objectives You will be able to: Write programs that define and use enumeration variables. Write programs that.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
 Constructor  Finalize() method  this keyword  Method Overloading  Constructor Overloading  Object As an Argument  Returning Objects.
Object-Oriented Programming Chapter Chapter
Static. 2 Objectives Introduce static keyword –examine syntax –describe common uses.
Section 3 - Arrays and Methods. Arrays Array: collection of group of data variables of same type, sharing the same name for convenience - Easy to search.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Objects and Variables Local variables – Confined to single context: allocated on stack – Primitive types such as int or object references – Must be initialized.
ISBN Object-Oriented Programming Chapter Chapter
Introduction to C# 2.0 An Advanced Look Adam Calderon Principal Engineer - Interknowlogy Microsoft MVP – C#
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
Object Oriented Software Development 4. C# data types, objects and references.
CMSC 202 Advanced Section Classes and Objects: Object Creation and Constructors.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
Session 1 C# Basics.
Introduction to C# By: Abir Ghattas Michel Barakat.
(c) University of Washington06-1 CSC 143 Java Inheritance Tidbits.
FEN 2014UCN Teknologi/act2learn1 Object-Oriented Programming “ The Three Pillars of OOP”: Encapsulation Inheritance Polymorphism The Substitution Principle.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Session 02 Module 3: Statements and Operators Module 4: Programming constructs Module 5: Arrays.
Object-Oriented programming in C++ Classes as units of encapsulation Information Hiding Inheritance polymorphism and dynamic dispatching Storage management.
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
COMP Inheritance and Polymorphism Yi Hong June 09, 2015.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Chapter 9 Introduction to Arrays Fundamentals of Java.
Value Types. 2 Objectives Discuss concept of value types –efficiency –memory management –value semantics –boxing –unboxing –simple types Introduce struct.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Modern Programming Tools And Techniques-I
2.7 Inheritance Types of inheritance
CS360 Windows Programming
CS 302 Week 11 Jim Williams, PhD.
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
Lecture 9 Concepts of Programming Languages
Conditional Statements
CIS 199 Final Review.
ENERGY 211 / CME 211 Lecture 17 October 29, 2008.
Lecture 9 Concepts of Programming Languages
Presentation transcript:

Language Fundamentals in brief C# - Introduction

C# All program logic must be embedded in (typically) a class. Every executable program must contain a Main- method. The Main-method is the starting point of the application. C# is case-sensitive No multiple inheritance (only between interfaces) All classes inherit object Garbage-collection C# supports operator and method overloading

A class public class Book { private string title; private string author; public Book(string t, string a) //Constructor { title= t; author= a; } public override string ToString(){ return (title+" "+author); }

Driver Program (Main) public class BookMain { public static void Main() { Book b1= new Book("C#","Troelsen"); Book b2= new Book("Java","Kölling"); System.Console.WriteLine(b1.ToString()); System.Console.WriteLine(b2); }

C# - Namespaces and Using Namespaces is a tool for structuring programs and systems Makes it possible to use the same names (identifiers) in different parts of an application. Namespaces may be nested Visual Studio creates default a namespace with the same name as the project using tells the compiler where to look for definitions that our program refers to Namespaces are not the same as Java-packages, but they are used for the same things and there are similarities

C# - value- and reference-types Objects of value-type are stack allocated – objects of reference type are allocated on the heap Value types die, when control goes out of the scope, where they are declared – reference types are removed by the garbage collector Value types are copied with assignment – with reference types a reference (the address) is copied

C# - reference types - example creation, assignment and comparison: Customer c1, c2, c3; string s1, s2; c1 = new Customer("Flemming Sander", 36259); c2 = new Customer(”Bjarne Riis", 55298); c3 = null; // c3 refers to nothing c3 = c1; // c3 refers to the same object as c1 if (c1 == null)... // is c1 referring to something? if (c1 == c2)... // compare references if (c1.Equals(c2))... // compares object-values

C# - When are objects equal? Classes ought to override the Equals-method public class Customer {. public override bool Equals(object obj) { Customer other; if ((obj == null) || (!(obj is Customer))) return false; // surely not equal other = (Customer) obj; // explicit typecast return this.id == other.id; // equal if ids are... }

C# - Boxing and Unboxing C# converts automatically between simple value and object value => object = "boxing“ (the value is “wrapped in a box”) object => value = "unboxing“ (the value is unwrapped again) int i, j; object obj; string s; i = 32; obj = i; // boxing (copy) i = 19; j = (int) obj; // unboxing! s = j.ToString(); // boxing! s = 99.ToString(); // boxing!

C# - arrays Arrays are reference types Created from the Array-class in FCL Created using the new-operator 0-based indexing Are initialised with default value (0 if numeric, null if reference) int[] a; a = new int[5]; a[0] = 17; a[1] = 32; int x = a[0] + a[1] + a[4]; int l = a.Length; Access element 1 Creation Number of elements

C# - structs In some ways like a class, but there are differences: Can have instance variables and methods Cannot have a default constructor Variables of a struct-type are value types and as such stack allocated Can only inherit from interfaces Cannot be inherited from Can be used to implement ADTs (Abstract Data Type), but no inheritance and polymorphism

C# - selection and iteration x = obj.foo(); if (x > 0 && x < 10) count++; else if (x == -1)... else {... } while (x > 0) {... x--; } for (int k = 0; k < 10; k++) {... }

C# - foreach-loop foreach loop is used to sweep over collections as arrays Reduces the risk of indexing errors int[] data = { 1, 2, 3, 4, 5 }; int sum = 0; foreach (int x in data) { sum += x; } foreach type value collection

C# - Methods A class may have two kind of methods: Instance methods Static methods (class methods) Instance methods need an object to be invoked Static methods are called using the class name only

C# - Example The array-class in BCL (FCL) The class is a member of namespace System (System.Array) namespace System { public class Array { public int GetLength(int dimension) {... } public static void Sort(Array a) {... }. } instance method static method

C# - calling the methods /* main.cs */ using System; public class App { public static void Main() { int[] data = { 11, 7, 38, 55, 3 }; Array.Sort(data); for (int i=0; i<data.GetLength(0); i++) Console.WriteLine(i + ": " + data[i]); } Class-method Instance-method