Questions tagged [c#-7.3]

For issues relating to development with C#, version 7.3. In most cases you should also specify the c# tag.

C# 7.3 is a version of the programming language. It ships with the 15.7 release of Visual Studio 2017.

86 questions
68
votes
15 answers

VS Code CSC : error CS1617: Invalid option '7.3' for /langversion

I downloaded VS 2017 15.7, .NET Core 2.1.2 and Blazor to try it out. It wasn't working in VS 2017 properly and thought I would try through the dotnet cli and VS Code. Instead I was met with the following error: CSC : error CS1617: Invalid option…
Spydernaz
  • 847
  • 2
  • 8
  • 14
64
votes
2 answers

C# 7.3 Enum constraint: Why can't I use the nullable enum?

Now that we have enum constraint, why doesn't compiler allow me to write this code? public static TResult? ToEnum(this String value, TResult? defaultValue) where TResult : Enum { return String.IsNullOrEmpty(value) ? defaultValue :…
Kirill Kovalenko
  • 2,121
  • 16
  • 18
28
votes
1 answer

C# 7.3 Enum constraint: Why can't I use the enum keyword?

To constrain a generic type parameter to be of an enum type, I previously constrained them like this, which was the best I could go for constraining type T for enums in pre-C# 7.3: void DoSomething() where T : struct, IComparable, IConvertible,…
Ray
  • 7,940
  • 7
  • 58
  • 90
25
votes
4 answers

Equality and polymorphism

With two immutable classes Base and Derived (which derives from Base) I want to define Equality so that equality is always polymorphic - that is ((Base)derived1).Equals((Base)derived2) will call Derived.Equals operators == and != will call Equals…
kofifus
  • 17,260
  • 17
  • 99
  • 173
15
votes
1 answer

Deconstruction is ambiguous

I have a vector class with two deconstruction methods as follows: public readonly struct Vector2 { public readonly double X, Y; ... public void Deconstruct( out double x, out double y ) { x = this.X; y = this.Y; …
Chris
  • 5,442
  • 17
  • 30
15
votes
1 answer

Why is a generic type constrained by 'Enum' failing to qualify as a 'struct' in C# 7.3?

If I have a generic interface with a struct constraint like this: public interface IStruct where T : struct { } I can supply an enumeration as my type T like so, because an enum satisfies a struct constraint: public class EnumIsAStruct :…
Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
14
votes
1 answer

How is it that a struct containing ValueTuple can satisfy unmanaged constraints, but ValueTuple itself cannot?

Consider the following types: (int, int) → managed. struct MyStruct { public (int,int) Value; } → unmanaged! Problem: A non-generic structure MyStruct, which has a managed member (int,int) has been evaluated as managed type. Expected Behavior: A…
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
13
votes
2 answers

How do I check if a type fits the unmanaged constraint in C#?

How do I check if a type T fits the unmanaged type constraint, such that it could be used in a context like this: class Foo where T : unmanaged? My first idea was typeof(T).IsUnmanaged or something similar, but that isn't a property/field of the…
John
  • 598
  • 2
  • 7
  • 22
12
votes
1 answer

Implicit static constructor called before Main()

I have the following piece of codes. class Program { static void Main(string[] args) { Enterprise.Initialize("Awesome Company"); // Assertion failed when constructor of 'Reg' class is disabled. Debug.Assert(Reg.Root…
Noctis Tong
  • 459
  • 1
  • 7
  • 17
10
votes
1 answer

Struct pointer (address), and default constructor

Does taking address of a C# struct cause default constructor call? For example, I got such structs: [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct HEADER { public byte OPCODE; public byte…
lisz
  • 435
  • 5
  • 9
10
votes
1 answer

Is a Span pointing to Fixed Sized Buffers without a fixed expression possible?

I'm using .NET Core 2.1 and language standard 7.3. I wish to reference a fixed buffer without obtaining a pointer to it. Is it currently possible? public unsafe struct InteropStruct { private fixed byte dataField[32]; public Span
Gamma_Draconis
  • 179
  • 1
  • 11
9
votes
1 answer

Can I use C# 7.3 with .Net Framework 4.6.1?

I'm interested in enum generic constraints, but when I'm switching language version for project on Build → Advanced I'm still getting error «not available in C#5; please use language version 7.3 or greater» even after reopening the project. Project…
Troll the Legacy
  • 675
  • 2
  • 7
  • 22
9
votes
1 answer

Why can a full property in C# be overridden with only a getter but it can still be set?

I came across a behavior that surprises me. Given the following two classes: class Parent { public virtual bool Property { get; set; } } class Child : Parent { public override bool Property { get => base.Property; } } I can write code…
rory.ap
  • 34,009
  • 10
  • 83
  • 174
8
votes
1 answer

Writing byte array to Span and sending it with Memory

I am receiving a buffer and i want from it to create a new buffer ( concatenating bytes prefixed,infixed and postfixed) and send it later on to a socket. Eg: Initial buffer: "aaaa" Final buffer: "$4\r\naaaa\r\n" (Redis RESP Protocol - Bulk…
Bercovici Adrian
  • 8,794
  • 17
  • 73
  • 152
7
votes
1 answer

Why can ValueTuple not be const?

ValueTuple types, declared as fields, can be mutable: class Foo { (int, int) bar = (0, 1); } or readonly: class Foo { readonly (int, int) bar = (0, 1); } and this (im)mutability applies to each member. I would expect it to be stretched to…
Alex Butenko
  • 3,664
  • 3
  • 35
  • 54
1
2 3 4 5 6