13. Primary Constructors
Partial Types
If a class is declared in multiple parts, only one
of those parts can declare a constructor
parameters and only that part can declare
parameters on the specification of the base
class.
14. Using Static
using System;
class Program
{
static void Main()
{
Console.WriteLine(Math.Sqrt(3 * 3 + 4 * 4));
}
}
using System;
class Program
{
static void Main()
{
Console.WriteLine(Math.Sqrt(3 * 3 + 4 * 4));
}
}
using System.Console;
using System.Math;
class Program
{
static void Main()
{
WriteLine(Sqrt(3 * 3 + 4 * 4));
}
}
15. Using Static
Extension Methods
using System.Linq.Enumerable; // Just the type, not the whole namespace
class Program
{
static void Main()
{
var range = Range(5, 17);
var odd = Where(range, i => i % 2 == 1);
var even = range.Where(i => i % 2 == 0);
}
}
using System.Linq.Enumerable; // Just the type, not the whole namespace
class Program
{
static void Main()
{
var range = Range(5, 17); // Allowed
var odd = Where(range, i => i % 2 == 1); // Not Allowed
var even = range.Where(i => i % 2 == 0); // Allowed
}
}
16. Declaration Expressions
if (int.TryParse(s, out int i)) { … }
GetCoordinates(out var x, out var y);
Console.WriteLine("Result: {0}", (int x = GetValue()) * x);
if ((string s = o as string) != null) { … s … }
from s in strings
select int.TryParse(s, out int i) ? i : -1;
20. Extension Add Methods in Collection
Initializers
On the first implementation of collection initializers in C#,
the Add methods that get called couldn’t be extension
methods.
VB got it right from the start, but it seems C# had been
forgoten.
This has been fixed: the code generated from a collection
initializer will now happily call an extension method called
Add.
It’s not much of a feature, but it’s occasionally useful, and it
turned out implementing it in the new compiler amounted
to removing a check that prevented it.
22. Indexed Members
var customer = new JsonData
{
$first = "Anders", // => ["first"] = "Anders"
$last = "Hejlsberg" // => ["last"] = "Hejlsberg"
};
string first = customer.$first; // => customer["first"]
23. Await in catch and finally blocks
Resource res = null;
try
{
// You could do this.
res = await res.OpenAsync(…);
…
}
catch (ResourceException e)
{
// Now you can do this …
await res.LogAsync(res, e);
}
finally
{
// … and this.
if (res != null) await res.CloseAsync();
}
24. Expression-Bodied Members
public class Point(int x, int y)
{
public int X => x;
public int Y => y;
public double Dist => Math.Sqrt(x* x + y* y);
public Point Move(int dx, int dy) => new Point(x + dx, y + dy);
}
37. References
The Future of C# - //build/ 2014
– http://channel9.msdn.com/Events/Build/2014/2-577
What’s New for C# Developers - //build/ 2014
– http://channel9.msdn.com/Events/Build/2014/9-020
Anders Hejlsberg Live Q&A - //build/ 2014
– http://channel9.msdn.com/Events/Build/2014/9-010
The Future of Visual Basic and C# - TechEd North America 2014
– http://channel9.msdn.com/Events/TechEd/NorthAmerica/2014/DEV-B336
Channel 9 Live: .NET Framework Q&A - TechEd North America 2014
– http://channel9.msdn.com/Events/TechEd/NorthAmerica/2014/C9-22
38. References
C# – Novas Funcionalidades do C# 6.0 – Antevisão de Abril de 2014
– http://www.revista-programar.info/artigos/c-novas-funcionalidades-do-c-6-0-antevisao-de-abril-
de-2014/
A C# 6.0 Language Preview
– http://msdn.microsoft.com/en-us/magazine/dn683793.aspx
45. Próximas reuniões presenciais
31/05/2014 – Maio (Lisboa)
21/06/2014 – Junho (Lisboa)
27/07/2014 – Julho (Lisboa)
??/??/???? – ????? (Porto)
Reserva estes dias na agenda! :)
Hinweis der Redaktion
Para quem puder ir preenchendo, assim não chateio mais logo
É importante para recebermos nós feedback, e para darmos feedback aos nossos oradores
http://goqr.me/