Skip to content

Syntax Error #18733

Closed
Closed

Description

@Sampleeeee

In the example, this is the code

public class SampleEventArgs
{
    public SampleEventArgs(string s) { Text = s; }
    public String Text { get; } // readonly
}

public class Publisher
{
    // Declare the delegate (if using non-generic pattern).
    public delegate void SampleEventHandler(object sender, SampleEventArgs e);

    // Declare the event.
    public event SampleEventHandler SampleEvent;

    // Wrap the event in a protected virtual method
    // to enable derived classes to raise the event.
    protected virtual void RaiseSampleEvent()
    {
        // Raise the event in a thread-safe manner using the ?. operator.
        SampleEvent?.Invoke(this, new SampleEventArgs("Hello"));
    }
}

On line 4, there is an issue. String is capitalized when it shouldn't be.

public String Text { get; } // readonly

It should be

public string Text { get; }; // readonly

Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Activity

  1. added
    help wanted
    and removed
    ⌚ Not Triaged
    on Jun 2, 2020
  2. IEvangelist commented on Jun 2, 2020

    @IEvangelist
    Member

    Hi @SamBehner - thank you for posting this issue. As long as there was a using System; at the top of the C# file - it is fine to use String, as string is an alias to the proper System type. But I agree, and I do prefer string. I've marked this issue as "up-for-grabs", feel free to create a pull request to address this issue and we'll happily review it.

    Also, one small correction - you added an extra ; at the end which is not needed. Should be this:

    public string Text { get; } // readonly
  3. Sampleeeee commented on Jun 2, 2020

    @Sampleeeee
    Author

    Oh, I was not aware oh this. I think it would be better to use string though as it seems more common, and it would match most of the other examples in the documentation

  4. added a commit that references this issue on Jun 3, 2020
    33d3b1a
  5. added a commit that references this issue on Jun 3, 2020
    ca5a5ed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dotnet-csharp/svchelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions