C# Compiler Error
CS0206 – A property or indexer may not be passed as an out or ref parameter
Reason for the Error
You will get this error in your C# program when you try to pass a property as ref or out parameter.
For example, try to compile the below code snippet.
namespace DeveloperPubNamespace { class Program { public static int Id { get; set; } public void ProcessData(ref int id) { Id = 0; } static void Main() { ProcessData(ref Id); } } }
This program will result with the error code CS0206 because Id is a Property in the class Program and we are trying to pass it as ref parameter to the function ProcessData.
Error CS0206 A property or indexer may not be passed as an out or ref parameter ConsoleApp3 C:\Users\Senthil\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 13 Active
Solution
In C#, a property is not allowed to be passed as ref or out parameter. You should not be passing property as ref/out parameter to avoid this error.