C#: Udtryk og metoder. Indhold “With regards to programming statements and methods, C# offers what you would come to expect from a modern OOPL…” Udtryk.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Execute Blocks of Code Multiple Times Svetlin Nakov Telerik Corporation
Composite: Shapes Organisation State Observer Design Patterns.
FEN IntroJava2006 AAU1 Nedarvning Specialisering/Generalisering Subklasse/Superklasse Statisk/Dynamisk type Polymorfi Interfaces.
1 | 2010 Activity og GUI Android Brugergrænseflade.
ASP.NET Arkitektur og Web Forms. Agenda – Web Forms Arkitektur for ASP.NET ( 1 del ) –Arkitekturen i korte træk –Fordele ved ASP.NET –Win Form Web.
ADO.NET (and more LINQ) Entity Framework (and more LINQ) Verification (CodeContracts) TPL (Task Parallel Library) Other.NET/C# topics.
static void Main() { int i = 0; if (i == 0) { int a = 5; int b = 15; if (a == 5) { int c = 3; int d = 99; }
Typeparametrisering Generel kode (generisk kode).
Implimentering af IComparable interfacet class Cirkel: IComparable { private long radius; // object memory :::::::::::::::::::::::::::::::::::::: #region.
Execute Blocks of Code Multiple Times Telerik Software Academy C# Fundamentals – Part 1.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 12 th -13 th Lecture Pavel Ježek.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
C# Language Report By Trevor Adams. Language History Developed by Microsoft Developed by Microsoft Principal Software Architect Principal Software Architect.
EC-241 Object-Oriented Programming
Language Fundamentals in brief C# - Introduction.
Reflection Reflection is the ability of a program to examine and modify the structure and behavior of an object at runtime.
BA1 JVM arkitektur BA2 Specifikation I The Java Virtual Machine Specification specificeres bl.a.: –De grundlæggende datatyper.
Programering af mobile enheder Windows Phone Rss Feed.
Tinaliah, S. Kom.. * * * * * * * * * * * * * * * * * #include using namespace std; void main () { for (int i = 1; i
Triana Elizabeth, S.Kom. #include using namespace std; void main () { for (int i = 1; i
Paradigmer i Programmering 4 a. Java 1.5 -Generics -Autoboxing/unboxing -New for sætning -Static imports -enum.
Arrays Session 05 Mata kuliah: M0874 – Programming II Tahun: 2010.
C# Console Application
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.
CS 4800 By Brandon Andrews.  Specifications  Goals  Applications  Design Steps  Testing.
Introduction to the C# Programming Language for the VB Programmer.
Repetition Statements Recitation – 02/20/2009 CS 180 Department of Computer Science, Purdue University.
COMP1180 Review Date: 4 March, 2009 Time: 10:30am - 12:20pm Venue: –CS students -- FSC801C and FSC801D –IS and other students -- OEE1017 Remarks: – 1)
ISBN Chapter 8 Statement-Level Control Structures.
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.
1. Database-systemer, introduktion1 1. Database-systemer Introduktion.
Jesper Mosegaard Multimedie Programmering E2003 MMProg uge44 Lingo grafik og animation.
C++ Control Flow Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th -22 nd Sept 2006.
4. Statements and Methods. 2 Microsoft Objectives “With regards to programming statements and methods, C# offers what you would come to expect from a.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
C#: Statements and Methods Based on slides by Joe Hummel.
FEN 2012 UCN Technology: Computer Science1 C# - Introduction Language Fundamentals in Brief.
Spring 2007NOEA: Computer Science Programme 1 C# - Introduction Language Fundamentals: Data Types string Objects and Classes Methods Iteration and Selection.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
C# Intro Programming languages and programs: Source code and object code Editors and compilers C# fundamentals: Program structure Classes and Objects Variables.
Programming Language C++ Xulong Peng CSC415 Programming Languages.
Current Assignments Homework 3 is due tonight. Iteration and basic functions. Exam 1 on Monday.
VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
ILM Proprietary and Confidential -
C# Programming Fundamentals Control Flow Jim Warren, COMPSCI 280 S Enterprise Software Development.
ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class.
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.
FEN NOEA/IT: Advanced Computer Studies 1 Patterns The concept of patterns originates from architecture (Christopher Alexander, 1977): “Each pattern.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Session 02 Module 3: Statements and Operators Module 4: Programming constructs Module 5: Arrays.
1 st Semester Module4-1 Iteration statement - while อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
1 st Semester Module 7 Arrays อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering Department.
Features of.net Language independent Object oriented program Multi threading Exception handling Drag and drop Linq
1 Statements © University of Linz, Institute for System Software, 2004 published under the Microsoft Curriculum License.
C syntax (simplified) BNF. Program ::= [ ] Directives ::= [ ] ::= | |… ::=#include > ::=#define.
Arkitektur, klasser og ansvar
Compound Condition Break , Continue Switch Statements in Java
Unit-1 Introduction to Java
Comparison between different LCA methods in regard to fire protection
Chapter 8: Control Structures
CS360 Windows Programming
Lecturer: Mukhtar Mohamed Ali “Hakaale”
null, true, and false are also reserved.
Stack Memory 2 (also called Call Stack)
Alkoholisme behandling. Alkoholisme og ordet alkoholiker er stadigvæk tabu.
Module 2 Variables, Assignment, and Data Types
Program Flow.
Programming Language C Language.
Presentation transcript:

C#: Udtryk og metoder

Indhold “With regards to programming statements and methods, C# offers what you would come to expect from a modern OOPL…” Udtryk Metoder

Part 1 Udtryk…

Udtryk i C# C# har standard udtrykene… Værditildeling Subrutiner og funktionskald Betingelser if, switch Iteration for, while, do-while Control Flow return, break, continue, goto

Eksempler 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++) {... }

Andre udtryk C# har også… iteration gennem en datastruktur via foreach namespace importering via using

foreach Specialiceret foreach løkke til sweep gennem f.eks array reducerer risiko for indekserings fejl Giver read only tilgang int[] data = { 1, 2, 3, 4, 5 }; int sum = 0; foreach (int x in data) { sum += x; } foreach typevaluecollection

using using direktiv giver adgang til klasser i et namespace uden at skulle angive det hver gang // before Workshop.Customer c; c = new Workshop.Customer("joe hummel", 94652); //after using Workshop; Customer c; c = new Customer("joe hummel", 94652); namespace Workshop { public class Customer {. } public class Product {. }

Et eksempel using direktiv(er) angives i toppen af filen /* main.cs */ using System; using Workshop; public class App { public static void Main() { Customer c; c = new Customer("joe hummel", 94652); Console.WriteLine( c.ToString() ); } namespace Workshop { public class Customer {. } public class Product {. }

Part 2 Metoder…

Typer af methoder Klasser kan indeholde 2 typer af methoder: instance static Instance methoder forudsætter instancering af et objekt Static methoder er globale og kræver kun klassenavnet

Eksempel Array klassen i FCL fully-qualified name is System.Array namespace System { public class Array { public int GetLength(int dimension) {... } public static void Sort(Array a) {... }. } instance metode (static ikke angivet) static metode (static angivet)

Metodekald Metodekald i Array klassen: /* 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]); }

Andre nyttige static metoder Et program til addere 2 heltal og udskrive summen: using System; public class Calculator { public static void Main() { string input, output; int a, b, sum; Console.Write("Enter first integer: "); input = Console.ReadLine(); a = Convert.ToInt32(input); Console.Write("Enter second integer: "); input = Console.ReadLine(); b = Convert.ToInt32(input); sum = a + b; output = String.Format("{0} + {1} = {2}", a, b, sum); Console.WriteLine(output); }

Opsummering Standardudtryk, og et par ikke-standard assignment, if, for, while, foreach, using To typer of metoder instance metoder kræver et objekt static metoder er globale og kræver kun en klasse