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

前端 未结 2 1771
青春惊慌失措
青春惊慌失措 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:13

    Optional parameters have been introduced with .NET 4.0 in C#, I am not sure what you are building with VS 2008 targetting an older framework, but I would say you should use them only in VS 2010 and .NET 4.0 Named and Optional Arguments

    0 讨论(0)
  • 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#.

    0 讨论(0)
提交回复
热议问题