-
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 :confused:
-
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);
}
-
do i really have to put that class in another namespace?
-
Everything's got to be under a namespace...
-
lol but i am under the form1 namespace lol
-
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.