O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

How Will C# 7 Probably Look Like

288 visualizações

Publicada em

New C# language constructs currently in development, which will probably be included in C# 7

Publicada em: Software
  • Login to see the comments

  • Seja a primeira pessoa a gostar disto

How Will C# 7 Probably Look Like

  1. 1. Kakšen bo verjetno C# 7? Damir Arh, Razum d.o.o., Microsoft MVP
  2. 2. Agenda • C# danes • Novosti v C# 7 • Visual Studio „15“
  3. 3. Kratka zgodovina C# Generiki (2005) LINQ (2007) dynamic (2010) async (2012) Roslyn (2015)
  4. 4. Kaj je Roslyn? • Nova implementacija prevajalnika • Prevajalnik kot storitev • Odprtokodni projekt
  5. 5. Ključne teme C# 7 • Delo s podatki • Učinkovitost • Poenostavitev
  6. 6. Ujemanje vzorcev • Objektni jeziki – Vnaprej znane operacije – Enostavno dodajanje podatkovnih tipov – Polimorfizem • Funkcionalni jeziki – Vnaprej znani podatkovni tipi – Enostavno dodajanje operacij – Ujemanje vzorcev
  7. 7. Visual Studio „15“ Preview 4 Ujemanje vzorcev
  8. 8. Kaj smo videli? • Operator „is“ z deklaracijo spremenljivke • Stavek „switch“ z ločevanjem po tipu • Dodatni pogoj v stavku „case“
  9. 9. Terke public (int weight, int count) Stocktake(IEnumerable<IWeapon> weapons) { var w = 0; var c = 0; foreach (var weapon in weapons) { w += weapon.Weight; c++; } return (w, c); }
  10. 10. Prirejanje vrednosti terk var inventory = Stocktake(weapons); Debug.WriteLine($"Item count: {inventory.count}"); Debug.WriteLine($"Item weight: {inventory.weight}"); (var inventoryWeight, var inventoryCount) = Stocktake(weapons); Debug.WriteLine($"Item count: {inventoryCount}"); Debug.WriteLine($"Item weight: {inventoryWeight}"); (var inventoryWeight, *) = Stocktake(weapons); Debug.WriteLine($"Item weight: {inventoryWeight}");
  11. 11. Razstavljanje tipov public static void Deconstruct(this Sword sword, out int damage, out int durability) { damage = sword.Damage; durability = sword.Durability; } var sword = new Sword {Damage = 5, Durability = 7}; (var damage, var durability) = sword; Debug.WriteLine($"Sword damage rating: {damage}"); Debug.WriteLine($"Sword durability: {durability}");
  12. 12. Lokalne funkcije static void ReduceMagicalEffects (this IWeapon weapon, int timePassed) { double decayRate = CalculateDecayRate(); double GetRemainingEffect(double currentEffect) => currentEffect * Math.Pow(decayRate, timePassed); weapon.FireEffect = GetRemainingEffect(weapon.FireEffect); weapon.IceEffect = GetRemainingEffect(weapon.IceEffect); }
  13. 13. public void LocalVariableByReference() { var terrain = Terrain.Get(); ref TerrainType terrainType = ref terrain.GetAt(4, 2); Assert.AreEqual(TerrainType.Grass, terrainType); terrain.BurnAt(4, 2); Assert.AreEqual(TerrainType.Dirt, terrainType); } public ref TerrainType GetAt(int x, int y) => ref terrain[x, y]; Vračanje vrednosti po referenci
  14. 14. Optimizacija asinhronih klicev private async ValueTask DoWorkAsync(bool doRealWork) { if (doRealWork) { await DoRealWorkAsync(); } }
  15. 15. Telesa metod v obliki izrazov public Grunt(int health) => _health = health >= 0 ? health : 0; ~Grunt() => Debug.WriteLine("Finalizer called"); private int _health; public int Health { get => _health = 0; set => _health = value >= 0 ? value : 0; }
  16. 16. Izjeme v izrazih public Grunt(int health) => _health = health >= 0 ? health : throw new ArgumentOutOfRangeException();
  17. 17. Izboljšave konstant const int MAX_PLAYER_LEVEL = 0b0010_1010; const int MAX_PLAYER_XP = 10_000_000; const uint RED_COLOR = 0xFF_00_00_FF;
  18. 18. Visual Studio „15“ Preview 4 • Implementirana večina predstavljenih novosti • Izjeme – Ignoriranje vrnjenih vrednosti terk – Optimizacija asinhronih klicev – Telesa metod v obliki izrazov – Izjeme v izrazih • Podpora terkam zahteva dodaten paket
  19. 19. Kaj je na voljo danes? • Praktični preizkus • Spremljanje objav na GitHubu • Sodelovanje v diskusijah • Prevod in preizkus izvorne kode • …
  20. 20. DNC Magazine
  21. 21. Viri • http://bit.ly/vs15preview4 • https://github.com/dotnet/roslyn/ • http://bit.ly/RoslynLanguageRoadmap • http://bit.ly/DncCSharp7 • http://bit.ly/DncRoslynOverview
  22. 22. @DamirArh http://www.damirscorner.com

×