-3

Is there a way to solve this? I'm new at this and I don't understand... I tried to fix this with other posts, but I have no idea...

public uint AddAllItemsByDefindex (int defindex, uint numToAdd = 0)

the error "Default parameter specifiers are not permitted" appears at the "=" symbol.

If you need to know something else from the code to help me: Screenshot from development environment showing the compiler error

CompuChip
  • 9,143
  • 4
  • 24
  • 48
  • 2
    What C# version are you using? This has been answered before – JohnD Dec 09 '13 at 22:13
  • 1
    And http://stackoverflow.com/questions/7822450/default-parameter-specifiers-are-not-permitted – JohnD Dec 09 '13 at 22:14
  • can you post the full code? I can compile just fine with no problems. which .NET Framework version are you using and which IDE version? 2010? 2012? 2013? – Ahmed ilyas Dec 09 '13 at 22:15

1 Answers1

6

Default parameters are only allowed as of C# 4.0. The screenshot shows you are using Visual Studio 2008, which works with .NET 2.0 - 3.5.

Make sure you compile against .NET 4.0 (you need to get VS2010 or higher), or create a overload of the function:

public uint AddAllItemsByDefindex (int defindex, uint numToAdd)
{
   // Use defindex and numToAdd
}

public uint AddAllItemsByDefindex (int defindex)
{
   return AddAllItemsByDefindex(defindex, 0);
}
CompuChip
  • 9,143
  • 4
  • 24
  • 48
  • i'm doing something wrong.. :/ – user3084676 Dec 09 '13 at 22:24
  • http://img834.imageshack.us/img834/3516/ox8z.png – user3084676 Dec 09 '13 at 22:26
  • Yes, you are definitely doing something wrong. No offense, but it looks like you don't have a clue what a class or function looks like. The part from line 280 onwards should be within the curly braces of line 273/274. – CompuChip Dec 09 '13 at 22:28
  • There appeared more errors about default parameters... how could I fix this all? ;/ I don't wanna waste your time – user3084676 Dec 09 '13 at 22:39
  • You can use the same trick. Can I recommend that you pickup a book on programming though, because you don't seem to really get the concept of function overloading. – CompuChip Dec 09 '13 at 22:41
  • You said that this could work... is there a program like VisualStudio with net framework 4.0 free? – user3084676 Dec 09 '13 at 22:43
  • @user3084676 yes, go to [this page](http://www.visualstudio.com/en-us/downloads) and go to the section called "Visual Studio Express 2013 for **Windows Desktop**" (The desktop part is important, the one just called "Visual Studio Express 2013 for Windows" is only for Windows 8 App Store apps, you are creating Desktop Apps), that is free and does what you want to do. (If you are a student you can get the Professional edition for free too, see the banner at the bottom of the section) – Scott Chamberlain Dec 09 '13 at 22:45
  • I need windows 7 to install that progam... Is there another option? I have Windows XP sp3.. I tried installing Visual Studio 2010, but i'm getting too many errors... I could still use Microsoft C# 2008 express, but it still have errors to repair. – user3084676 Dec 11 '13 at 20:40