Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C# Readonly function

how do i make a Property in C# readonly ?

I tried to do the C# Property

  public string Title { get;  }
    public  abstract string? Html { get;  }
    public int RatingCount => UserEmail.Count;
    public decimal? AverageRating { get
    {
        decimal sum = UserEmail.Values.Sum();
        return RatingCount > 0 ? (sum / RatingCount) : null;
    }}
    private List<Comment> _comment { get; } = new();
    public IReadOnlyList<Comment> Comments => _comment.AsReadOnly();

    private readonly Dictionary<string, int> UserEmail = new();
    
    public Post(User user, string title)
    {
        uesr = user;
        Title = title;
    }

this is a descrption for what happend

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Look at this example, I hope it solves your question:

public class MyClass
{
    private readonly int _myField;

    public MyClass(int myField)
    {
        _myField = myField;
    }

    public int GetMyField()
    {
        return _myField;
    }
}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading