Microsoft.NET Вторая лекция. Reference and value types public class RefType { } public struct ValueType : IDisposable { public int A, B; public ValueType(int.

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 12 th -13 th Lecture Pavel Ježek.
Software Engineering Implementation Lecture 3 ASPI8-4 Anders P. Ravn, Feb 2004.
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.
Static Members, Structures, Enumerations, Generic Classes, Namespaces Learning & Development Team Telerik Software Academy.
Paradigmer i Programmering 4 a. Java 1.5 -Generics -Autoboxing/unboxing -New for sætning -Static imports -enum.
C# Types Tom Roeder CS fa. Administration CMS is up let me know if you can’t see the course Assignments are posted may not be able to do some.
CS 4800 By Brandon Andrews.  Specifications  Goals  Applications  Design Steps  Testing.
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 
Programming in C# Language Overview
SEG Object Oriented Analysis, Design and Programming
JAVA PROGRAMMING PART II.
Introduction to Classes and Objects (Through Ch 5) Dr. John P. Abraham Professor UTPA.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Advanced .NET Programming I 13th Lecture
BİL527 – Bilgisayar Programlama I Strings 1. Contents More on Variables – Type Conversions – Enumerations – Structs – Arrays – String Operations 2.
BIM313 – Advanced Programming Techniques Object-Oriented Programming 1.
CSCI 3328 Object Oriented Programming in C# Chapter 3: Introduction to Classes and Objects UTPA – Fall
Methods Session 04 Mata kuliah: M0874 – Programming II Tahun: 2010.
BIM313 – Advanced Programming Techniques Strings and Functions 1.
Interfaces 1. Interfaces are (parts of) contracts Interfaces are contracts between implementers and consumers Consumers: Programmers using a class implementing.
DEV300: Advanced C# Eric Gunnerson Program Manager Visual C# Microsoft Corporation.
Introduction to Building Windows 8.1 & Windows Phone Applications.
Session 08 Module 14: Generics and Iterator Module 15: Anonymous & partial class & Nullable type.
ILM Proprietary and Confidential -
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
Introduction to C#. Why C#? Develop on the Following Platforms ASP.NET Native Windows Windows 8 / 8.1 Windows Phone WPF Android (Xamarin) iOS (Xamarin)
1 Interfaces and Abstract Classes Chapter Objectives You will be able to: Write Interface definitions and class definitions that implement them.
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
AUC Technologies Projects Consulting, Development, Mentoring, and Training Company.NET Basic Fundamentals Presented By : Muhammad Atif Hussain Deputy Manager.
Variables and Data Types.  Variable: Portion of memory for storing a determined value.  Could be numerical, could be character or sequence of characters.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX.
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.
Oct 2007 SDP-MSc Slide 1 Section 9 Graphic Programming.
Generics Generics vs. heterogeneous collections Doing your own generics FEN 2014UCN Teknologi/act2learn1.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 8 th Lecture Pavel Ježek
BİL527 – Bilgisayar Programlama I Functions 1. Contents Functions Delegates 2.
CSC 298 Streams and files.
CSC Java Programming, Spring, 2010 Week 2: Java Data Types, Control Constructs, and their C++ counterparts.
Introduction to C# Anders Hejlsberg Distinguished Engineer Developer Division Microsoft Corporation.
A DVANCED P ROGRAMMING C HAPTER 4: I NTRODUCTION TO I NTRODUCTION TO C LASSES, O BJECTS, M ETHODS AND STRINGS Dr Shahriar Bijani Winter 2016.
Computer Programs CS 1400 Dennis A. Fairclough Version 1.1 CS 1400 Dennis A. Fairclough Version 1.1.
Introduction to Web Application
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming II 5 th Lecture Pavel Ježek
© Copyright SELA software & Education Labs Ltd Baruch Hirsch St.Bnei Brak Israel 1 בס " ד.
Object Oriented Programming Lecture 2: BallWorld.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 2 nd Lecture Pavel Ježek
C++ Lesson 1.
C# for C++ Programmers 1.
Basic Introduction to C#
Advanced .NET Programming I 2nd Lecture
C# - OOP TTU IT College , Autumn SEMESTER Andres käver.
BİL527 – Bilgisayar Programlama I
University of Central Florida COP 3330 Object Oriented Programming
Computing with C# and the .NET Framework
Reserved Words.
Dr Shahriar Bijani Winter 2017
null, true, and false are also reserved.
Conditional Statements
Introduction to Java Programming
Variables, Loops, Decision Statements, etc
JavaScript Reserved Words
class PrintOnetoTen { public static void main(String args[]) {
The important features of OOP related to C#:
Module 2 Variables, Assignment, and Data Types
Welcome back to Software Development!
鄭士康 國立台灣大學 電機工程學系/電信工程研究所/ 資訊網路與多媒體研究所
Presentation transcript:

Microsoft.NET Вторая лекция

Reference and value types public class RefType { } public struct ValueType : IDisposable { public int A, B; public ValueType(int a, int b) { A = a; B = b; } public void Dispose() { /* Do some work */ } }

Встроенные типы Value types: bool b;int i; byte by;uint ui; sbyte sby; long l; char c; ulong ul; decimal dec; short s; double d; ushort us; float f; Reference types: object o;string str;

Enums public enum MyEnum { MyValue1, MyValue2, MyValue3 } //... MyEnum val = MyEnum.MyValue1; //... switch (val) { case MyEnum.MyValue1: //... break; case MyEnum.MyValue2: //... break; }

Массивы int[] arr = new int[4]; int[] arr2 = new int[] { 1, 2, 3 }; int[,] arr_2d = new int[,] { {1, 3}, {5, 7} }; int[][] arr_jagged = new int[3][]; for (int i = 0; i < arr_jagged.Length; ++i) arr_jagged[i] = new int[i + 10];

Методы с переменным количеством параметров public static int Max(params int[] numbers) { if (numbers.Length < 1) throw new ArgumentException(); int cur_max = numbers[0]; foreach (int number in numbers) cur_max = Math.Max(cur_max, number); return cur_max; } //... int i = Max(3, 5, 4, 234); int[] arr = new int[] { 2, 3, 6, 3, 98 }; i = Max(arr);

Перегрузка операторов public struct Complex { public double Re, Im; public Complex(double re, double im) { Re = re; Im = im; } public Complex(double re) : this(re, 0) { } public static Complex operator + (Complex l, Complex r) { return new Complex(l.Re + r.Re, l.Im + r.Im); } public static implicit operator Complex(double re) { return new Complex(re); } }

Использование перегруженных операторов static void Main(string[] args) { Complex z1 = 0; Complex z2 = z1 + z1.Re; }

Generics public class Wrapper { private readonly T _val; public Wrapper(T val) { _val = val; } public static implicit operator T(Wrapper wrapper) { return wrapper._val; } public static implicit operator Wrapper (T val) { return new Wrapper (val); } }

Generics public T Max (params T[] values) where T : IComparable { if (values.Length < 1) throw new ArgumentException(); T cur_max = values[0]; foreach (T val in values) if (cur_max.CompareTo(val) < 0) cur_max = val; return cur_max; }

Оператор foreach static void Main(string[] args) { foreach (string s in args) Console.WriteLine(s); }

IEnumerable interface interface IEnumerable { IEnumerator GetEnumerator(); } interface IEnumerator { public bool MoveNext(); public void Reset(); public object Current { get; } }

Delegates public class GDIContext { /*... */ } public class Window { public delegate void OnPaintProc(GDIContext gdi); public OnPaintProc OnPaint; //... } private static void DrawCircle(GDIContext gdi) { /*... */ } static void Main(string[] args) { Window wnd = new Window(); wnd.OnPaint += DrawCircle; }

Exceptions try { throw new Exception("Hello, world!!!"); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.WriteLine("Finally block executed."); }

IDisposable interface public class Device : IDisposable { public Device() { /*... */ } public void Dispose() { GC.SuppressFinalize(this); /*... */ } ~Device() { Dispose(); } }

Оператор using using (Device dev = new Device()) { //... throw new Exception("Hello, world!!!"); }

Reflection Assemblies –MyClassLibrary.dll –MyExecutable.exe Types –MyClassLibrary.SomeNamespace.MyClass –MyClassLibrary.SomeNamespace.MyClass.Nested Methods, Properties, etc –MyClassLibrary.SomeNamespace.MyClass.DoWork() –MyClassLibrary.SomeNamespace.MyClass.SomeValue

Reflection static void PrintMethods(Type type) { foreach(MethodInfo method in type.GetMethods()) { Console.WriteLine(method); } } static void Main(string[] args) { PrintMethods(typeof(int)); }

Attributes class EnumValueAttribute : Attribute { private readonly string _valueName; public EnumValueAttribute(string valueName) { _valueName = valueName; } public string ValueName { get { return _valueName; } } }

Attributes public enum WindowMessage { [EnumValue("Изменение размеров")]Resize, [EnumValue("Перерисовка")]Paint, [EnumValue("Нажатие кнопки")]KeyDown } [Serializable] public class MyClass { [NonSerialized] protected int i; public double D; }

Reflection.Emit Возможность создавать во время выполнения новые Сборки Типы Методы и т.д. А также добавлять новые сущности к уже существующим