|
-
Oct 11th, 2002, 07:23 AM
#1
Thread Starter
yay gay
Enumerations
i have an enumeration in a class...and i want that 1 function has a parameter that uses that enumeration...how do i do that? i want that when in form1 i type mClass.mFunction i can put in there my enumeration as parameter..i tryed puting the enumeration as public but didnt work
-
Oct 11th, 2002, 09:34 AM
#2
Make sure your enum is public, then it's fairly straight forward:
PHP Code:
namespace MyNamespace
{
public enum enumMyEnum
{eElement1 = 0, eElement2, eElement3}
public class Test
{
public Test()
{
}
public string MyFunction(enumMyEnum p_enumParameter)
{
return p_enumParameter.ToString();
}
}
}
You either have to add a namaspace to your form or use a full qualifyer for the enum:
PHP Code:
private void button1_Click(object sender, System.EventArgs e)
{
string strSomeValue;
MyNamespace.Test objMyClass = new MyNamespace.Test();
strSomeValue = objMyClass.MyFunction(MyNamespace.enumMyEnum.eElement1);
}
-
Oct 11th, 2002, 11:24 AM
#3
Thread Starter
yay gay
do i really have to put that class in another namespace?
-
Oct 11th, 2002, 11:30 AM
#4
Hyperactive Member
Everything's got to be under a namespace...
-scott
he he he
-
Oct 11th, 2002, 11:31 AM
#5
Thread Starter
yay gay
lol but i am under the form1 namespace lol
-
Oct 11th, 2002, 12:20 PM
#6
Frenzied Member
If you are making creating that class in form1 then thats ok, however If you are creating the class in a separate file, then you can either use the form1 namespace or create a new one.
Dont gain the world and lose your soul
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|