Skip to content

Enhance properties with top-level statements #81141

@stbau04

Description

@stbau04

Properties are disallowed in files with top-level statements. Is this actually expected behavior?
If so, the current error error CS0116: A namespace cannot directly contain members such as fields, methods or statements could be enhanced, as statements/methods are in fact allowed in the same location

using System;

Console.WriteLine("Hello world!");

int X { get; set; }
int X() => 0;

https://sharplab.io/#v2:CYLg1APgAgTAjAWAFDKnAnACgEQAkCmANoQPYAEA7iQE6HACE2AlANzLICWAdgC5kAaZAN5kA5vh4syAZwlSAvp14DMTMgF4AfGQAMLIA===

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CompilersConcept-Diagnostic ClarityThe issues deals with the ease of understanding of errors and warnings.help wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions