A brief history of
( it's 5.0 )
(the one with async/await)
¯\_(ツ)_/¯
To find this later, google "C# 7 features."
Real language support, not just System.Tuple
public (double meanAge, int oldest) GetAgeStats(IEnumerable<Person> people)
{
var mean = people.Average(x => x.Age);
var max = people.Max(x => x.Age);
var result = (meanAge: mean, oldest: max);
return result;
}
(var mean, var oldest) = GetAgeStats(people);
Dog - regular reference we have today
Dog! - a reference which cannot be null
Dog? - a reference which might be null
public destructible struct ImageResource
{
...
~Cleanup() { ... }
}
public class Celsius(double Temperature);
public class Fahrenheit(double Temperature);
public class Cartesian(double X, double Y);
public class Polar(double r: Radius, double phi: Angle);
public class Fahrenheit(double Temperature)
{
public bool operator is(Celsius c) { ... }
}
var someTemp = Fahrenheit(212.0); //don't need new
if(someTemp is Celsius(100.0))
{
//someTemp is boiling
}
var v = foo as Video;
if (v != null) {
//code using v
}
becomes
if (foo is Video v) {
//code using v
}
//v doesn't exist
abstract class Shape;
class Square(double Width, double Height) : Shape;
class Circle(double Radius) : Shape;
public double GetArea(Shape shape) {
switch(shape) {
case Square(1.0, 1.0): return 1.0;
case Square s: return s.Width * s.Height;
case Circle c: return Math.PI * c.Radius * c.Radius;
}
}
(sorry if you're colorblind)