Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

Compiler Error CS1908

The type of the argument to the DefaultValue attribute must match the parameter type

This error is generated when you use the wrong argument for the DefaultValueAttribute attribute value. Use a value that matches the parameter type.

The following sample generates CS1908.

// CS1908.cs
// compile with: /target:library
using System.Runtime.InteropServices;

public interface ISomeInterface
{
   void Bad([Optional] [DefaultParameterValue("true")] bool b);   // CS1908

   void Good([Optional] [DefaultParameterValue(true)] bool b);   // OK
}

Community Additions

ADD
Show:
© 2015 Microsoft