1 / 15

C# Podstawy Cz. 2

C# Podstawy Cz. 2. Krzysztof Fediuk krzysiek.fediuk@gmail.com. Zaczynamy. Sprawdzian Encje w C# TaskManager. Na start. using System; using System.Collections.Generic ; using System.Linq ; using System.Text ; namespace ConsoleApplication1 { class Program {

jerzy
Télécharger la présentation

C# Podstawy Cz. 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C#PodstawyCz. 2 Krzysztof Fediuk krzysiek.fediuk@gmail.com

  2. Zaczynamy • Sprawdzian • Encje w C# • TaskManager

  3. Na start using System; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; namespace ConsoleApplication1 { classProgram { staticvoidMain(string[] args) { } } }

  4. Przestrzeń nazw/Paczka • Powinna odzwierciedlać przeznaczenie • Lub grupę powiązanych logicznie elementów namespace<Pełna.Nazwa.Oddzielona.Kropkami> namespace ConsoleApplication1.Main

  5. Przestrzeń nazw/paczka - użycie • Deklarujemy używanie typów • Można deklarować aliasy – w razie konfliktów using <namespace_name>; using<typename> = <namespace_name>.<type>; usingSystem.Collections.Generic; using File = TaskManager.CommonUtils.File;

  6. Klasa • Podstawowa jednostka obiektowości • Powinna się znajdować w namespace • Można ponownie wykorzystać – dziedziczenie class<nazwa_klasy> classProgram classGenericList

  7. Pola • Przechowywanie wartości • Powinny być prywatne <kwalifikator> <nazwa_typu> <nazwa_zmiennej>; intala; string ola; WindowmainWindow,secondaryWindow; doublew = 0.0;

  8. Metody • Nazywamy z dużej litery <kwalifikator> <zwracana_wartość> <nazwa_metody>(<parametry>) public staticvoidMain(string[] args) privatedoubleComputeValue(intargValue)

  9. Properties (właściwości) • Zachowanie podobne do pól • Nazewnictwo metod • Enkapsulacja danych <nazwa_typu> <nazwa_zmiennej>{ get{…} set{…}} publicintLength { get{ return _length;} set { if (value > 0) _length = value; }

  10. Eventy • Delegaty • Programowanie zdarzeniowe event<nazwa_typu> <nazwa_zmiennej> eventEventHandlerNameChanged; NameChanged += <delegat>; NameChanged();

  11. Wyjątki • Klasa bazowa Exception • try … catch … finally DbConnection.Open(); try { //… thrownewException(); } catch (Exception e) { Log(e);} finally { DbConnection.Close();}

  12. Pozostałe struktury • Interfejs • Tylko deklaracje metod, propertisów i eventów • Enum • Wartości poprzedzane nazwą typu • Struktura • Kopiowana przez wartość interfaceIFile{} interfaceSerializable{} enumDaysOfWeek { Monday,…} structPoint { doublexCoordinate; doubleyCoordinate;}

  13. Dziedziczenie • Struktura drzewa • Pień – klasy • Konary – interfejsy • Klasa • Musi implementować interfejsy • Interfejs • Nielimitowane dziedziczenie

  14. Do dzieła • Stwórzcie nową solucję – TaskManager • Nazwa projektu – TaskManager • Namespace – TaskManager.Data • Klasa – Task • Name • Description • StartDate • Completed

  15. Do dzieła • Interfejs ITask • Klasy BasicTask i ExtendedTask • Extended zawiera kolekcję ITask

More Related