Book a Demo

Author Topic: C# code generation: Default parameter specifiers  (Read 3614 times)

DJ_Doena

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
C# code generation: Default parameter specifiers
« on: July 14, 2005, 07:19:51 am »
If I design a class and a method with a parameter that has a default value, C# code generation will generate this:

Code: [Select]
public class Foo
{
  public Foo()
 {
 }

 public void DoSomething(int i = 0)
 {
 }
}


That will bring the following error message:

Quote
Visual C# Language Concepts  

Compiler Error CS0241Default parameter specifiers are not permitted

Method parameters cannot have default values. Use method overloads if you want to achieve the same effect.

The following sample generates CS0241:

// CS0241.cs
public class TestClass
{
   public void TestMethod(int i = 9)   // CS0241
   // try the following line instead
   // public void TestMethod(int i)
   {
   }

   public static void Main()
   {
      TestClass x = new TestClass();
      x.TestMethod(9);
   }
}


--------------------------------------------------------------------------------

Send feedback on this topic to Microsoft

© Microsoft Corporation. All rights reserved.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: C# code generation: Default parameter specifie
« Reply #1 on: July 14, 2005, 05:51:37 pm »
This should be fixed in the next build of EA.

Until then, either don't model parameter default values for C# classes, or modify the C# parameter template and remove the last line.

Simon