Please explain what the problem is - what error message or whatever are you getting? Your code seems in principle correct.
Svante
AxCrypt - Free Open Source File Encryption & Online Password Manager - http://www.axantum.com [Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.
csrinivas28
Member
2 Points
10 Posts
How to Create Array Of Enums in c#
May 01, 2008 02:29 PM|LINK
Hi
I wan to create array of enums in c# .In one of my dll method I need to pass array of enums as parameter.
public void SetPermissions(string queuename,string machinename,AccessRights[]permissions)
{
}
where AccessRights is a array of enums.
public enum AccessRights
{
DeleteMessage,FullControl
}
Can anyone help me how to do this.urgent please
Thanks and Regards
sri
gbogea
Contributor
4019 Points
576 Posts
Re: How to Create Array Of Enums in c#
May 01, 2008 03:05 PM|LINK
Is this what you want?
public enum AccessRights { FullControl, None } class Enums { public void Caller() { AccessRights[] rights = new AccessRights[3]; rights[0] = AccessRights.FullControl; rights[1] = AccessRights.None; rights[2] = AccessRights.FullControl; MyMethod(rights); //or AccessRights[] rights2 = { AccessRights.FullControl, AccessRights.FullControl, AccessRights.None }; MyMethod(rights2); } public void MyMethod(AccessRights[] rights) { } }-----------------
Please 'Mark as Answer' the post(s) that helped you
Hamlin
Member
49 Points
10 Posts
Re: How to Create Array Of Enums in c#
May 01, 2008 03:07 PM|LINK
Apart from needing a space between the AccessRights[] and permissions you example looks ok, are you getting a specific error?.
I just tested this and it worked fine:
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { SomeName[] enums = { SomeName.Item1, SomeName.Item2 }; TestMethod(enums); Console.WriteLine("Press any key..."); Console.ReadLine(); } static void TestMethod(SomeName[] enumArray) { Console.WriteLine("in TestMethod()"); foreach (SomeName item in enumArray) { Console.WriteLine(item.ToString()); } } } enum SomeName { Item1, Item2, Item3 } }Svante
All-Star
18347 Points
2300 Posts
Re: How to Create Array Of Enums in c#
May 01, 2008 04:17 PM|LINK
Please explain what the problem is - what error message or whatever are you getting? Your code seems in principle correct.
AxCrypt - Free Open Source File Encryption & Online Password Manager - http://www.axantum.com
[Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.
csrinivas28
Member
2 Points
10 Posts
Re: How to Create Array Of Enums in c#
May 01, 2008 04:30 PM|LINK
gbogea
Many Thanks for your quick reply.This is what I am looking for.Really appreciate your sample.Once again Thank you very much.
Thanks and Regards
sri
csrinivas28
Member
2 Points
10 Posts
Re: How to Create Array Of Enums in c#
May 01, 2008 04:32 PM|LINK
Hi Svante
Solved my problem.Appreciate your response.
Thanks and Regards
Sri
csrinivas28
Member
2 Points
10 Posts
Re: How to Create Array Of Enums in c#
May 01, 2008 04:34 PM|LINK
Hi Hamlin
Appreciate your code.My problem was solved.Thank you very much for posting answer to my question.Keep it up.
Thanks and Regards
Sri