difference in the behavior of optionalAttribute (used to declare an optional parameter) in VS 2010 vs VS 2008

前端 未结 2 1772
青春惊慌失措
青春惊慌失措 2021-01-05 03:42

A simple C# method with an optional parameter declared using the OptionalAttribute as

namespace  ClassLibrary11
{
   public class Class1
   {
      public in         


        
2条回答
  •  天涯浪人
    2021-01-05 04:25

    simply put, it's because C# 3.5 doesn't support optional parameters. As per MSDN,

    Note that the DefaultParameterValueAttribute does not add support for default parameters to languages that do not support this feature. For example, if you use the DefaultParameterValueAttribute with a method written in C#, which does not support default parameters, you cannot use the default parameter when calling the method from C#.

提交回复
热议问题