runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Question: Why C# doesn't allow passing parameter as final?

Open AhmedRagheb opened this issue 9 years ago • 2 comments

In Java, you can mark variable as final

public void GetById(final int id)
{
    // Get by id and don't change id 
}

Why this is not allowed in C#. There are many questions like this in Stackoverflow but I prefer to ask here to get the right reason behind that, not just theoretical answers.

AhmedRagheb avatar Nov 21 '17 08:11 AhmedRagheb

This is a question/suggestion for the csharplang repo, not coreclr. I'm pretty sure they already have some discussions around allowing readonly to be used for local variables.

mikedn avatar Nov 21 '17 08:11 mikedn

Ok, I will close it and move it there. Thanks,

AhmedRagheb avatar Nov 21 '17 08:11 AhmedRagheb