Click here to Skip to main content
16,016,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I am trying to use an enum as a optional parameter. But i get en error saying "identifier expected". Can anyone tell me how to use enum;
I have tried the following code;
C#
enum attachmentType { filePath , fileString}; 
public static void SendEmail(attachmentType = attachmentType.filePath)
{
  // Do stuff
}

I have also found this link[^]. It is a similar question but the answer is not satisfactory.

Thanks in advance.
Posted
Updated 6-Aug-13 22:01pm
v2

You still need to declare a name for parameter. Try changing it to;

C#
public enum attachmentType { filePath , fileString};

public static void SendEmail(attachmentType type = attachmentType.filePath)
{
  // Do stuff
}



Hope this helps,
Fredrik
 
Share this answer
 
Comments
wonder-FOOL 7-Aug-13 4:10am    
Thank you
Fredrik Bornander 7-Aug-13 4:12am    
Glad I could help.

Also, don't forget to bump the access level of the enum to the same as the function accepting it as a parameter, otherwise you'll get a "inconsistent access level" error.

/Fredrik
Manas Bhardwaj 7-Aug-13 4:11am    
You beat me. :) +5!
Fredrik Bornander 7-Aug-13 4:12am    
You snooze, you lose! :)
Should be like this:

C#
enum attachmentType { filePath , fileString};
public static void SendEmail(attachmentType type = attachmentType.filePath)
{
  // Do stuff
}


You are missing the parameter name.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900