7. int count = 5;
string label = "Colors used in the map";
var pair = (count: count, label: label);
int count = 5;
string label = "Colors used in the map";
var pair = (count, label); // element names are "count" and "label"
https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-1#inferred-tuple-element-names
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.1/infer-tuple-names.md
15. void M!<D>(D d) where D : Delegate { }
void M2<E>(E e) where E : Enum { }
unsafe void M3<T>(T *p) where T : unmanaged { }
https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-3#enhanced-generic-constraints
16. var tuple = ("", 10);
if (tuple == ("", 10)) // true
if (("", 10) == (null, 5.2)) // false
if (("", 1, true) == (false, 5))
/*
Error CS8384
Tuple types used as operands of an == or != operator must have matching
cardinalities. But this operator has tuple types of cardinality 3 on the left
and 2 on the right.
*/
https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-3#tuples-support--and-
https://github.com/dotnet/csharplang/issues/190
17. public class B
{
public B(int i, out int j) => j = i;
}
public class D : B
{
public D(int i) : base(i, out var j)
{
WriteLine($"The value of 'j' is {j}");
}
}
https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-3#extend-expression-variables-in-initializers
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/expression-variables-in-initializers.md
18. [field: SomeThingAboutFieldAttribute]
public int SomeProperty { get; set; }
https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-3#attach-attributes-to-the-backing-fields-for-auto-implemented-properties
https://github.com/dotnet/csharplang/issues/42
20. unsafe struct S
{
public fixed int myFixedField[10];
}
class C
{
static S s = new S();
unsafe public void M()
{
fixed (int* ptr = s.myFixedField)
{
int p = ptr[5];
}
}
}
unsafe struct S
{
public fixed int myFixedField[10];
}
class C
{
static S s = new S();
unsafe public void M()
{
int p = s.myFixedField[5];
}
}
https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-3#indexing-fixed-fields-does-not-require-pinning
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/indexing-movable-fixed-fields.md
30. class Person(string First, string Last);
class Person : IEquatable<Person>
{
public string First { get; }
public string Last { get; }
public Person(string First, string Last) => (this.First, this.Last) = (First, Last);
public void Deconstruct(out string First, out string Last) => (First, Last) = (this.First, this.Last);
public bool Equals(Person other) => other != null && First == other.First && Last == other.Last;
public override bool Equals(object obj) => obj is Person other ? Equals(other) : false;
public override int GetHashCode() => GreatHashFunction(First, Last);
…
}