C# Error CS0685 – Conditional member ‘{0}’ cannot have an out parameter

C# Error

CS0685 – Conditional member ‘{0}’ cannot have an out parameter

Reason for the Error & Solution

Conditional member ‘member’ cannot have an out parameter

When using the attribute on a method, that method may not have an out parameter. This is because the value of the variable used for the out parameter would not be defined in the case that the method call is compiled to nothing. To avoid this error, remove the out parameter from the conditional method declaration, or don’t use the Conditional Attribute.

Example

The following sample generates CS0685:

// CS0685.cs  
using System.Diagnostics;  
  
class C  
{  
    [Conditional("DEBUG")]  
    void trace(out int i)  // CS0685  
    {  
        i = 1;  
    }  
}  

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...