1) int i = int.Parse("99"); 2) delegate void IntMethodInvoker(uint x); 3) delegate double TwoLongsOp(long first, long second); 4) delegate string GetAString();

Slides:



Advertisements
Similar presentations
Execute Blocks of Code Multiple Times Svetlin Nakov Telerik Corporation
Advertisements

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.
Public class ABC { private int information = 0; private char moreInformation = ‘ ‘; public ABC ( int newInfo, char moreNewInfo) { } public ABC () {} public.
C# Language Report By Trevor Adams. Language History Developed by Microsoft Developed by Microsoft Principal Software Architect Principal Software Architect.
Language Fundamentals in brief C# - Introduction.
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.
Язык JavaScript Скриптовый язык для выполнения на html-страницах.
November Ron McFadyen1 Façade simplifies access to a related set of objects by providing one object that all objects outside the set use to.
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.
Some Principles of Animation. 1. SQUASH and STRETCH: Use stretched drawings to create the illusion of speed and squashed drawings to show weight. Remember.
Crossword Puzzle Solver Michael Keefe. Solver structure.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Performing Simple Calculations with C# Svetlin Nakov Telerik Corporation
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.
Introduction to Classes and Objects (Through Ch 5) Dr. John P. Abraham Professor UTPA.
.NET Data types. Introduction ٭ A "data type" is a class that is primarily used just to hold data. ٭ This is different from most other classes since they're.
1. 2 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Decisions { class.
BİL527 – Bilgisayar Programlama I Strings 1. Contents More on Variables – Type Conversions – Enumerations – Structs – Arrays – String Operations 2.
FEN 2012 UCN Technology: Computer Science1 C# - Introduction Language Fundamentals in Brief.
3. Declaring Value-Type Variables
Spring 2007NOEA: Computer Science Programme 1 C# - Introduction Language Fundamentals: Data Types string Objects and Classes Methods Iteration and Selection.
CSCI 3328 Object Oriented Programming in C# Chapter 3: Introduction to Classes and Objects UTPA – Fall
Extension Methods, Anonymous Types LINQ Query Keywords, Lambda Expressions Based on material from Telerik Corporation.
Methods Session 04 Mata kuliah: M0874 – Programming II Tahun: 2010.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 3A Integral Data (Concepts)
1) int[] myArray; 2) myArray = new int [ 4 ] ; 3) Переменная myArray ссылается на четыре целочисленных значения в управляемой куче.
Effective C#, Chapter 1: C# Language Elements Last Updated: Fall 2011.
STATEMENTS AND FLOW OF EXECUTION CHAPTER 11 OF APRESS A PROGRAMMERS GUIDE TO C SHARP 5.0.
Session 08 Module 14: Generics and Iterator Module 15: Anonymous & partial class & Nullable type.
Chapter 6—Objects and Classes The Art and Science of An Introduction to Computer Science ERIC S. ROBERTS Java Objects and Classes C H A P T E R 6 To beautify.
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
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,
ITF11006.NET The Basics. Data Types – Value Types – Reference Types Flow Control – Conditional – Loop Miscellaneous – Enumerations – Namespaces Class.
Problems.Net Анатолий Крыжановский Обра. ООП 2 class Bar { } void Foo(object a) { Console.WriteLine("object"); } void Foo(object a, object b) { Console.WriteLine("object,
Bill Campbell, UMB Microsoft's.NET C# and The Common Language Runtime.
Exercise 2 Introduction to C# CIS Create a class called Employee that contains the following private instance variables: Social Securitystring.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 10 th Lecture Pavel Ježek
C# - variablesBjørk Busch1 Variables Basic types (also defined as classes with methods) : Integer-types Int, long, byte, sbyte, short, ushort, uint, ulong.
Microsoft.NET Вторая лекция. Reference and value types public class RefType { } public struct ValueType : IDisposable { public int A, B; public ValueType(int.
Generics Ashima Wadhwa. What are generics Generics were added by C# 2.0 the term generics means parameterized types. Using generics, you can define a.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 8 th Lecture Pavel Ježek
Text Files and String Processing
CNS 3260 C# .NET Software Development
CSC 298 Streams and files.
Chapter One Lesson Three DATA TYPES ©
A: A: double “4” A: “34” 4.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
Introduction to C# Anders Hejlsberg Distinguished Engineer Developer Division Microsoft Corporation.
33) static void Main() { Action operations = MathOperations.MultiplyByTwo; operations += MathOperations.Square; ProcessAndDisplayNumber(operations, 2.0);
Enum,Structure and Nullable Types Ashima Wadhwa. Enumerations, Enumerations, or enums, are used to group named constants similar to how they are used.
Computer Programs CS 1400 Dennis A. Fairclough Version 1.1 CS 1400 Dennis A. Fairclough Version 1.1.
1 C++ Classes and Data Structures Course link…..
C# Basic Syntax, Visual Studio, Console Input / Output
C# Basic Syntax, Visual Studio, Console Input / Output
C# — Console Application
Computing with C# and the .NET Framework
Reserved Words.
Chapter 2.
Implementing Polymorphism
Review Operation Bingo
C# Control Statements part 1 (Based on Deitel Book)
בניית מחלקות.
CSCI 3328 Object Oriented Programming in C# Chapter 3: Introduction to Classes and Objects UTPA – Fall 2012 This set of slides is revised from lecture.
Data Types Imran Rashid CTO at ManiWeber Technologies.
The important features of OOP related to C#:
Module 2 Variables, Assignment, and Data Types
Presentation transcript:

1) int i = int.Parse("99"); 2) delegate void IntMethodInvoker(uint x); 3) delegate double TwoLongsOp(long first, long second); 4) delegate string GetAString(); 5) public delegate string GetAString(); 6) private delegate string GetAString(); static void Main() { int x = 40; GetAString firstStringMethod = new GetAString(x.ToString) ; Console.WriteLine("Строка равна " + firstStringMethod()) ; // С firstStringMethod, инициализированным x.ToString(), // приведенный оператор эквивалентен следующему: // Console.WriteLine("Строка равна " + х.ToString()); 7) firstStringMethod(); firstStringMethod.Invoke(); 8) GetAString firstStringMethod = new GetAString(x.ToString); 9) GetAString firstStringMethod = x.ToString;

10) struct Currency { public uint Dollars; public ushort Cents; public Currency(uint dollars, ushort cents) { this.Dollars = dollars; this.Cents = cents; } public override string ToString() { return string.Format("${0}.{1,2:00}", Dollars,Cents); } public static string GetCurrencyUnit() { return "Доллар"; }

public static explicit operator Currency (float value) { checked { uint dollars = (uint)value; ushort cents = (ushort)((value-dollars)*100); return new Currency(dollars, cents); } public static implicit operator float (Currency value) { return value.Dollars + (value.Cents/100.0f); } public static implicit operator Currency (uint value) { return new Currency(value, 0); } public static implicit operator uint (Currency value) { return value.Dollars; }

11) private delegate string GetAString () ; static void Main() { int x = 40; GetAString firstStringMethod = x.ToString; Console.WriteLine("Строка равна {0}", firstStringMethod()); Currency balance = new Currency(34, 50); // firstStringMethod ссылается на метод экземпляра firstStringMethod = balance.ToString; Console.WriteLine("Строка равна {0}", firstStringMethod()); // firstStringMethod ссылается на статический метод firstStringMethod = new GetAString(Currency.GetCurrencyUnit); Console.WriteLine ("Строка равна {0}", firstStringMethod()) ; } 12) Строка равна 40 Строка равна $34.50 Строка равна Доллар

13) class MathsOperations { public static double MultiplyByTwo(double value) { return value*2; } public static double Square(double value) { return value*value; } 14) using System; namespace SimpleDelegate { delegate double DoubleOp(double x); class MainEntryPoint { static void Main() {

DoubleOp [] operations = { MathsOperations.MultiplyByTwo, MathsOperations.Square } for (int i=0; i<operations.Length; i++) { Console.WriteLine("Использование operations[{0}]:",i); ProcessAndDisplayNumber(operations[i], 2.0); ProcessAndDisplayNumber(operations[i], 7.94); ProcessAndDisplayNumber(operations[i], 1.414); Console.WriteLine(); } static void ProcessAndDisplayNumber(DoubleOp action, double value) { double result = action(value); Console.WriteLine( "Значение равно {0}, результат операции равен {1}”,value,result); }

15) ProcessAndDisplayNumber(operations[i], 2.0); 16) - operations[i]  означает делегата (т.е. метод, представленный делегатом); - operations[i](2.0)  означает вызов метода делегата с передачей, ему параметров в скобках. 17) static void ProcessAndDisplayNumber(DoubleOp action, double value) 18) double result = action(value); 19) Использование operations[0]: Значение равно 2, результат операции равен 4 Значение равно 7.94, результат операции равен Значение равно 1.414, результат операции равен Использование operations[1] : Значение равно 2, результат операции равен 4 Значение равно 7.94, результат операции равен Значение равно 1.414, результат операции равен ) delegate double DoubleOp(double x); 21) Func [] operations = { MathOperations.MultiplyByTwo, MathOperations.Square } ;

22) double value) { double result = action(value); Console.WriteLine( "Значение равно {0}, результат операции равен (1}", value, result); } 23) bool swapped = true; do { swapped = false; for (int i = 0; i < sortArray.Length - 1; i++) { if (sortArray[i] < sortArray[i+1])) //проблема с этой проверкой { int temp = sortArray[i]; sortArrayt[i] = sortArray[i + 1]; sortArray[i + 1] = temp; swapped = true; } } while (swapped);

24) static public void Sort (IList sortArray, Func co mparison) 25) class BubbleSorter { static public void Sort (IList sortArray, Func comparison) { bool swapped = true; do { swapped = false; for (int i = 0; i < sortArray.Count - 1; i++) { if (comparison(sortArray[i+1], sortArray[i])) { T temp = sortArray[i]; sortArray[i] = sortArray[i + 1] ; sortArray[i + 1] = temp; swapped = true; } } while (swapped); }

26) class Employee { public Employee(string name, decimal salary) { this.Name = name; this.Salary = salary; } public string Name { get; private set; } public decimal Salary { get; private set; ) public override string ToString() { return string.Format("{0}, {1:C)", Name, Salary); } public static bool CompareSalary(Employee e1, Employee e2) { return e1.Salary < e2.Salary; }

27) using System; namespace Wrox.ProCSharp.Delegates { class Program { static void Main() { Employee [] employees = { new Employee("Bugs Bunny", 20000), new Employee("Elmer Fudd", 10000), new Employee("Daffy Duck", 25000), new Employee("Wiley Coyote", ), new Employee("Foghorn Leghorn", 23000), new Employee("RoadRunner", 50000)}; } BubbleSorter.Sort(employees, Employee.CompareSalary); foreach (var employee in employees) { Console.WriteLine(employee); }

28) Elmer Fudd, $10, Bugs Bunny, $20, Foghorn Leghorn, $23, Daffy Duck, $25, Road Runner, $50, Wiley Coyote, $1,000, ) class Program { static void Main() { Action operations = MathOperations.MultiplyByTwo; operations += MathOperations.Square; 30) Action operation1 = new MathOperations.MultiplyByTwo; Action operation2 = new MathOperations.Square; Action operations = operation1 + operation2;

31) class MathOperations { public static void MultiplyByTwo(double value) { double result = value*2; Console.WriteLine("Умножение на 2: (0} дает {1}",value,result); } public static void Square(double value) { double result = value*value; Console.WriteLine("Возведение в квадрат: {0} дает {1}", value, result); } 32) static void ProcessAndDisplayNumber(Action action, double value) { Console.WriteLine(); Console.WriteLine( "\nProcessAndDisplayNumber вызван со значением value = {0)" + value); action(value); }